216 web-safe colors chart
Today i was messing around with colors, and i found out how to create a we-safe color chart in php. here is the codei made. maybe this could be useful to someone...
http://www.newbie-developer.com/resources/216-colors/colors.php
<?
$ccr = array();
$ccr[0]="00";
$ccr[1]="33";
$ccr[2]="66";
$ccr[3]="99";
$ccr[4]="CC";
$ccr[5]="FF";
$f=0;
for($rv=0; $rv<6; $rv++) {
if($f == "1") {$colors.=""; $f=0;}
$r=$ccr[$rv];
for($gv=0; $gv<6; $gv++) {
$g=$ccr[$gv];
for($rb=0; $rb<6; $rb++) {
$b=$ccr[$rb];
$colors.="";
}
}
$f++;
}
echo "
216 Web-Safe Colors
$colors
";
?>
http://www.newbie-developer.com - Newbie web-developer community.
Mark Hensler posted this at 06:52 — 4th April 2002.
He has: 4,048 posts
Joined: Aug 2000
optimized PHP...
<?php
echo<<<myHTML
<html>
<head>
<style>
BODY, TD {
font-family: verdana, arial, monospace;
font-size: 12px;
}
</style>
</head>
<body bgcolor=\"#FFFFFF\">
<br />
<form name=\"myForm\" id=\"myForm\" action=\"\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"right\">
onMouseover:
</td>
<td>
<input type=\"text\" name=\"over\" size=\"7\" />
</td>
</tr>
<tr>
<td align=\"right\">
onClick:
</td>
<td>
<input type=\"text\" name=\"click\" size=\"7\" />
</td>
</tr>
</table>
</form>
<table bgcolor=\"#FFFFFF\" border=\"0\" cellspacing=\"5\" cellpadding=\"2\" align=\"center\">
<tr>
myHTML;
for ($r=0x00; $r<=0xFF; $r+=0x33) {
echo \" <td bgcolor=\\"#000000\\">\n\";
for ($g=0x00; $g<=0xFF; $g+=0x33) {
echo \" <table border=\\"0\\" cellspacing=\\"1\\" cellpadding=\\"0\\">\n\";
echo \" <tr>\n\n\";
for ($b=0x00; $b<=0xFF; $b+=0x33) {
printf(\" <td width=\\"20\\" height=\\"20\\" bgcolor=\\"#%02X%02X%02X\\" onMouseover=\\"document.myForm.over.value=this.bgColor\\" onClick=\\"document.myForm.click.value=this.bgColor\\"> </td>\n\", $r, $g, $b);
}
echo \" </tr>\n\";
echo \" </table>\n\";
}
echo \" </td>\n\";
if ($r==0x66) {
echo \" </tr>\n\";
echo \" \n<tr>\n\";
}
}
echo<<<myHTML
</tr>
</table>
</body>
</html>
myHTML;
?>
Ideally, you'd save the output to a static HTML page.
Mark Hensler
If there is no answer on Google, then there is no question.
korndragon posted this at 22:19 — 4th April 2002.
They have: 87 posts
Joined: Dec 2001
I didn't really post it here as a tool, but more for ppl to see how a loop, and the 216 color chart is set up...
http://www.newbie-developer.com - Newbie web-developer community.
korndragon posted this at 22:24 — 4th April 2002.
They have: 87 posts
Joined: Dec 2001
i see that it goes up by 33's, but how dows it get the CC, and the FF? would you explain it for me?
http://www.newbie-developer.com - Newbie web-developer community.
Mark Hensler posted this at 00:42 — 5th April 2002.
He has: 4,048 posts
Joined: Aug 2000
it's adding in hex.. (hex numbers start with 0x)
The printf() function allows you to format output.
%X tells it to output the integer value in uppercase hex format.
%02X tells it to print 2 hex digits and pad it with a zero.
If I just used %2X, it would output " 0 0 0" instead of "000000", so I had to pad it.
I used a hex counter because I could eliminate the array and extra 3 variables.
I then had the loop print rather than append a string, so I could eliminate the large string variable.
So now the script uses less resources.
The <<< is called the heredoc syntax.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.