note 61871 added to ref.image

From: Date: Tue, 14 Feb 2006 11:22:46 +0000
Subject: note 61871 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-103676@lists.php.net to get a copy of this message
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 -- http://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.php.net/manage/user-notes.php?action=delete+61871&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61871&report=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://master.php.net/manage/user-notes.php

« previous php.notes (#103676) next »