note 97218 added to function.hexdec
| From: | Adam at MyLearningUKLtd | Date: | Thu, 08 Apr 2010 16:15:02 +0000 |
| Subject: | note 97218 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168035@lists.php.net to get a copy of this message | ||
Here's a function I wrote to fade from one hex colour into another and returns all the colours
as a nice handy array.
Eg. $fade = hexFade('#ff0000','#00ff00',10);
/**
* Fade from start hex colour into another over x amount of steps
*
* @param mixed $hexStart Hex Colour to start. eg #ff0000
* @param mixed $hexEnd Hex Colour to end up with. eg. #ff00ff
* @param mixed $midSteps Steps to take to get from start colour to end colour
* @return array All colours used to get from start to finish, including start and finish.
*/
function hexFade($hStart,$hEnd,$midSteps=10){
$hStart = str_replace("#","",$hStart);
$hEnd = str_replace("#","",$hEnd);
$hS = array_map("hexdec",str_split($hStart,2));
$hE = array_map("hexdec",str_split($hEnd,2));
$cA = array("#$hStart");
for($i = $midSteps; $i >= 1; $i--){
$c1 = str_pad(dechex(($hS[0] - $hE[0])/($midSteps+1) * $i +
$hE[0]),2,"0",STR_PAD_LEFT);
$c2 = str_pad(dechex(($hS[1] - $hE[1])/($midSteps+1) * $i +
$hE[1]),2,"0",STR_PAD_LEFT);
$c3 = str_pad(dechex(($hS[2] - $hE[2])/($midSteps+1) * $i +
$hE[2]),2,"0",STR_PAD_LEFT);
$cA[] = "#$c1$c2$c3";
}
$cA[] = "#$hEnd";
return $cA;
}
----
Server IP: 69.147.83.197
Probable Submitter: 89.242.2.107
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- https://master.php.net/note/edit/97218
Del: integrated -- https://master.php.net/note/delete/97218/integrated
Del: useless -- https://master.php.net/note/delete/97218/useless
Del: bad code -- https://master.php.net/note/delete/97218/bad+code
Del: spam -- https://master.php.net/note/delete/97218/spam
Del: non-english -- https://master.php.net/note/delete/97218/non-english
Del: in docs -- https://master.php.net/note/delete/97218/in+docs
Del: other reasons-- https://master.php.net/note/delete/97218
Reject -- https://master.php.net/note/reject/97218
Search -- https://master.php.net/manage/user-notes.php