note 61871 deleted from ref.image by tularis

From: Date: Sun, 29 Jun 2008 21:02:54 +0000
Subject: note 61871 deleted from ref.image by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140927@lists.php.net to get a copy of this message
Note Submitter: relsqui at chiliahedron dot com ---- 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. ?>

« previous php.notes (#140927) next »