Click to See Complete Forum and Search --> : sequence of hexidecimal codes


perpetualshaun
06-26-2006, 11:35 AM
This is just a stab in the dark... doe anyone know where I could find the logic behind the hexidecimal codes? I'm trying to put 512 different color blocks on the screen, and would like to have it go from Black to white, then darkest red to lightest, darkest orange to lightest, etc. etc.

I've come up w/ a little PHP script that generates the codes:


function buildHexCodes() {

$hex_code_pts[] = 'ff';
$hex_code_pts[] = 'ee';
$hex_code_pts[] = 'dd';
$hex_code_pts[] = 'cc';
$hex_code_pts[] = '99';
$hex_code_pts[] = '66';
$hex_code_pts[] = '33';
$hex_code_pts[] = '00';

$part_1_array = $hex_code_pts;
$part_2_array = $hex_code_pts;
$part_3_array = $hex_code_pts;

while($part_1 = each($part_1_array)) {
while($part_2 = each($part_2_array)) {
while($part_3 = each($part_3_array)) {
$colors[] = $part_1['value'].$part_2['value'].$part_3['value'];
}
reset($part_3_array);
}
reset($part_2_array);
}
reset($part_1_array);
return $colors;
}


This isn't a horrible layout, but I'd prefer to have it from darkest to lightest, or vice-versa. I get 512 colors from this function as it is now, and am diplaying them in an HTML table, 32 columns across. The lighter colors (yellows, oranges, white, and reds) are in the top half of the table, and the bottom half has all the darker colors (greens, blues, purples, and grays and blacks). But the yellows aren't even close together; they're scattered all about the upper half.

Does anyone understand the logic behind the three parts of hexidecimal codes better than I, and may be able to offer some advise on changes I can make in my function to have the like colors closer together?


Thanks,

Shaun

Charles
06-26-2006, 11:41 AM
It's #RRGGBB or #RGB such that #ABC is the same as #AABBCC. The three digit version gives you the "web safe" colors. Equal red, blue and green values would give you a shade of grey.