65 Million Colours Later

I was bored, as usual, so I wrote a php script that would iterate through every possible colour combination in HEX. It crashed firefox, and as a GNOME member I feel it is my duty to log a bug ‘Firefox core dumps when HTML file of 352mb is opened’. I don’t think it would be appreciated.

Anyway, although I didn’t have the opportunity to test if it worked, here is the php script i wrote to do the job, it might not even be the correct algorithm! I piped the output to html in an attempt to relieve the stress on the browser, to little avail.

The output html file is SO LARGE that the command ‘wc -l’ returns 8, and I am sure that there are more than 8 lines, since doing a ‘less’ on the file nearly grinds my Intel Core i3 to a halt. I then attempted a (crazy) ‘nl <file>.html’ (which produced an output worthy of a shoddy 90’s trilogy with Lawrence Fishbourne)…for 10 minutes before the command eventually gave up.

<html><head></head><body>

<table width=100%><tr>
<?php

# RED
for ($r=16; $r<255; $r++)
{
for ($g=16; $g<255; $g++)
{
for ($b=16; $b<255; $b++)
{
if ($r >15)
{
$r_hex_integer = (int) ($r / 16);
$r_hex_remainder = $r % 16;

if ($r_hex_integer <10) { $digit1 = $r_hex_integer; }

if ($r_hex_integer == 10) { $digit1 = “A”; }
if ($r_hex_integer == 11) { $digit1 = “B”; }
if ($r_hex_integer == 12) { $digit1 = “C”; }
if ($r_hex_integer == 13) { $digit1 = “D”; }
if ($r_hex_integer == 14) { $digit1 = “E”; }
if ($r_hex_integer == 15) { $digit1 = “F”; }

if ($r_hex_remainder == 10) { $digit2 = “A”; }
if ($r_hex_remainder == 11) { $digit2 = “B”; }
if ($r_hex_remainder == 12) { $digit2 = “C”; }
if ($r_hex_remainder == 13) { $digit2 = “D”; }
if ($r_hex_remainder == 14) { $digit2 = “E”; }
if ($r_hex_remainder == 15) { $digit2 = “F”; }

if ($r_hex_remainder <10) { $digit2 = $r_hex_remainder; }

}
else
{
if ($r <10) { $digit1 = 0; $digit2 = $r; }
if ($r == 10) { $digit1 = “A”; $digit2 = 0; }
if ($r == 11) { $digit1 = “B”; $digit2 = 0; }
if ($r == 12) { $digit1 = “C”; $digit2 = 0; }
if ($r == 13) { $digit1 = “D”; $digit2 = 0; }
if ($r == 14) { $digit1 = “E”; $digit2 = 0; }
if ($r == 15) { $digit1 = “F”; $digit2 = 0; }
}
if ($g >15)
{
$g_hex_integer = (int) ($g / 16);
$g_hex_remainder = $g % 16;

if ($g_hex_integer <10) { $digit3 = $g_hex_integer; }

if ($g_hex_integer == 10) { $digit3 = “A”; }
if ($g_hex_integer == 11) { $digit3 = “B”; }
if ($g_hex_integer == 12) { $digit3 = “C”; }
if ($g_hex_integer == 13) { $digit3 = “D”; }
if ($g_hex_integer == 14) { $digit3 = “E”; }
if ($g_hex_integer == 15) { $digit3 = “F”; }

if ($g_hex_remainder == 10) { $digit4 = “A”; }
if ($g_hex_remainder == 11) { $digit4 = “B”; }
if ($g_hex_remainder == 12) { $digit4 = “C”; }
if ($g_hex_remainder == 13) { $digit4 = “D”; }
if ($g_hex_remainder == 14) { $digit4 = “E”; }
if ($g_hex_remainder == 15) { $digit4 = “F”; }

if ($g_hex_remainder <10) { $digit4 = $g_hex_remainder; }

}
else
{
if ($g <10) { $digit3 = 0; $digit4 = $g; }
if ($g == 10) { $digit3 = “A”; $digit4 = 0; }
if ($g == 11) { $digit3 = “B”; $digit4 = 0; }
if ($g == 12) { $digit3 = “C”; $digit4 = 0; }
if ($g == 13) { $digit3 = “D”; $digit4 = 0; }
if ($g == 14) { $digit3 = “E”; $digit4 = 0; }
if ($g == 15) { $digit3 = “F”; $digit4 = 0; }
}
if ($b >15)
{
$b_hex_integer = (int) ($b / 16);
$b_hex_remainder = $b % 16;

if ($b_hex_integer <10) { $digit5 = $b_hex_integer; }

if ($b_hex_integer == 10) { $digit5 = “A”; }
if ($b_hex_integer == 11) { $digit5 = “B”; }
if ($b_hex_integer == 12) { $digit5 = “C”; }
if ($b_hex_integer == 13) { $digit5 = “D”; }
if ($b_hex_integer == 14) { $digit5 = “E”; }
if ($b_hex_integer == 15) { $digit5 = “F”; }

if ($b_hex_remainder == 10) { $digit6 = “A”; }
if ($b_hex_remainder == 11) { $digit6 = “B”; }
if ($b_hex_remainder == 12) { $digit6 = “C”; }
if ($b_hex_remainder == 13) { $digit6 = “D”; }
if ($b_hex_remainder == 14) { $digit6 = “E”; }
if ($b_hex_remainder == 15) { $digit6 = “F”; }

if ($b_hex_remainder <10) { $digit6 = $b_hex_remainder; }

}
else
{
if ($g <10) { $digit5 = 0; $digit6 = $b; }
if ($b == 10) { $digit5 = “A”; $digit6 = 0; }
if ($b == 11) { $digit5 = “B”; $digit6 = 0; }
if ($b == 12) { $digit5 = “C”; $digit6 = 0; }
if ($b == 13) { $digit5 = “D”; $digit6 = 0; }
if ($b == 14) { $digit5 = “E”; $digit6 = 0; }
if ($b == 15) { $digit5 = “F”; $digit6 = 0; }
}
echo ‘<td bgcolor=”#’. $digit1. $digit2. $digit3. $digit4. $digit5. $digit6. ‘”>’;
echo ‘</td>’;
} #Close BLUE
echo ‘</tr><tr>’;
} #Close GREEN
} #Close RED
?>
</tr>
</table>
</body>

</html>

nl grinds to a halt:

Image

The size of the resulting HTML

Image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s