charris1980 Posted March 10, 2008 Share Posted March 10, 2008 right now i have a user choose a background color and a lighter background color to show next to it on a data row i am displaying. i was curious if there was a way that they could choose a background color (lets say blueish) and then through php code go about 4-6 shades lighter of the blueish color? Or if there is a different way to accomplish this I am open ears. I just want to eliminate users input as much as possible. Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/ Share on other sites More sharing options...
laffin Posted March 10, 2008 Share Posted March 10, 2008 They say when it comes to colors, colors on the oppsite side of the color wheel will compliment the primary color chosen. what better way than negate the color code? bgcolor= <user input> fgcolor = !<user input> Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-488837 Share on other sites More sharing options...
frijole Posted March 10, 2008 Share Posted March 10, 2008 can you explain how the ! can do that? it will give the opposite color? Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-488877 Share on other sites More sharing options...
laffin Posted March 11, 2008 Share Posted March 11, 2008 Yes, it will invert the numbers. function negativeColor($color) { //get red, green and blue $r = substr($color, 0, 2); $g = substr($color, 2, 2); $b = substr($color, 4, 2); //revert them, they are decimal now $r = 0xff-hexdec($r); $g = 0xff-hexdec($g); $b = 0xff-hexdec($b); //now convert them to hex and return. return dechex($r).dechex($g).dechex($b); } Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-489519 Share on other sites More sharing options...
frijole Posted March 11, 2008 Share Posted March 11, 2008 thats good to know. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-489608 Share on other sites More sharing options...
charris1980 Posted March 11, 2008 Author Share Posted March 11, 2008 yeah that is some good info about colors. i'll test this tonight and see how it goes! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-489610 Share on other sites More sharing options...
laffin Posted March 11, 2008 Share Posted March 11, 2008 Actually i did a test, and it did pretty well <?php function NegateColor($color) { return substr('000000'.dechex(~hexdec($color)),-6); } $colors=array('FFFFFF','000000','3300FF','660033','444444','336633'); echo "<TABLE>\n"; foreach($colors as $color) { $bgc = NegateColor($color); echo "<TR><TD BGCOLOR=\"#$bgc\"><FONT color=\"#$color\">$color on $bgc</FONT></TD></TR>\n"; } echo "</TABLE>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-489785 Share on other sites More sharing options...
laffin Posted March 11, 2008 Share Posted March 11, 2008 Went a little further to generate a random base color, and it works most of the time, some colors just blend into each other too well. <?php function NegateColor($color) { return substr('000000'.dechex(~hexdec($color)),-6); } echo "<TABLE>\n"; for($i=0;$i<10;$i++) { $color=dechex(mt_rand(0,hexdec('FFFFFF'))); $bgc = NegateColor($color); echo "<TR><TD BGCOLOR=\"#$bgc\"><FONT color=\"#$color\">$color on $bgc</FONT></TD></TR>\n"; } echo "</TABLE>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95496-weird-color-question-for-you/#findComment-489793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.