On the offchance someone else should need one, here's a
function you can use to randomly "mix" two
colors, resulting in a "child" color with
components of both. You might use it to come up with ideas
for a color scheme, for example; the image section seemed as
good a place for it as any.
<?php
// $mom and $dad should be integers, quite possibly the
output of hexdec().
// Similarly, the return value $child will be an integer
suitable for feeding to dechex().
breed_colors($mom, $dad) {
do { $maskhex .= rand()&1 ? "f" :
"0"; } while (strlen($maskhex) < 6);
$mask = hexdec($maskhex);
$inversemask = $mask ^ 16777215;
$child = ($mom & $mask) | ($dad &
$inversemask);
return $child;
}
// For example:
breed_colors(hexdec("012345"),
hexdec("6789ab"));
// Let's say the random mask was ff0f0f.
// The inverse mask is therefore 00f0f0.
// $mom & $mask == 010305.
// $dad & $inversemask == 0080a0.
// Those two |ed together make 0183a5, which combines the
traits of the parents into one $child.
?>
----
Server IP: 216.194.113.175
Probable Submitter: 66.92.15.102
----
Manual Page -- http://www
.php.net/manual/en/ref.image.php
Edit -- http://master.php.net/manage/user-notes.php?action=
edit+61871
Delete: added to the manual -- htt
p://master.php.net/manage/user-notes.php?action=delete+61871
&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.
php.net/manage/user-notes.php?action=delete+61871&report
=yes&reason=bad+code
Delete: spam -- http://master.php.
net/manage/user-notes.php?action=delete+61871&report=yes
&reason=spam
Delete: useless -- http://master.p
hp.net/manage/user-notes.php?action=delete+61871&report=
yes&reason=useless
Delete: non-english -- http://mast
er.php.net/manage/user-notes.php?action=delete+61871&rep
ort=yes&reason=non-english
Delete: already in docs -- http://
master.php.net/manage/user-notes.php?action=delete+61871&
;report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-
notes.php?action=delete+61871&report=yes
Reject -- http://master.php.net/manage/user-
notes.php?action=reject+61871&report=yes
Search -- http://ma
ster.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|