note 40913 added to function.dechex

From: Date: Thu, 18 Mar 2004 19:59:52 +0000
Subject: note 40913 added to function.dechex
Groups: php.notes 
Request: Send a blank email to php-notes+get-67037@lists.php.net to get a copy of this message
Here's my version of a red->yellow->green gradient: <?php function colorMeter($percent, $invert = false) { //$percent is in the range 0.0 <= percent <= 1.0 // integers are assumed to be 0% - 100% // and are converted to a float 0.0 - 1.0 // 0.0 = red, 0.5 = yellow, 1.0 = green //$invert will make the color scale reversed // 0.0 = green, 0.5 = yellow, 1.0 = red //convert (int)% values to (float) if (is_int($percent)) $percent = $percent * 0.01; $R = min((2.0 * (1.0-$percent)), 1.0) * 255.0; $G = min((2.0 * $percent), 1.0) * 255.0; $B = 0.0; return (($invert) ? sprintf("%02X%02X%02X",$G,$R,$B) : sprintf("%02X%02X%02X",$R,$G,$B)); } //colorMeter ?> and use it like this: <TABLE BORDER=1 WIDTH="300"> <?php for ($i = 0.0; $i <= 1.0; $i += 0.10) { $RGB = colorMeter($i); print "<TR><TD BGCOLOR='".$RGB."'>".$i."</TD><TD> <PRE>".$RGB."</PRE></TD></TR>\n"; } ?> </TABLE> <P> <TABLE BORDER=1 WIDTH="300"> <?php for ($i = 0; $i <= 100; $i += 10) { $RGB = colorMeter(intval($i), true); print "<TR><TD BGCOLOR='".$RGB."'>".$i."</TD><TD> <PRE>".$RGB."</PRE></TD></TR>\n"; } ?> </TABLE> ---- Manual Page -- http://www.php.net/manual/en/function.dechex.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40913 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40913&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40913&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67037) next »