I’m trying to create a swatch every color, which I’ll later have to match to the pixels of an image to create a mosaic.
As of now, it doesn’t display anything. I’m not sure if I’m running the loop correctly. It’s taking every number for $r$g$b then incrementing it and changing it to a hex format to be read and displayed.
Code is here:
$r = 000;
$g = 000;
$b = 000;
for($r = 000; $r <= 155; $r++) {
for($r = 000; $r <= 155; $r++) {
for($r = 000; $r <= 155; $r++) {
echo '<span style="width: 5px; height: 5px; background-color-color:#'.dechex($r).dechex($g).dechex($b).'">.</span>';
}
}
}
Thanks in advance!
Several issues here:
$r, which should probably be$r,$g, and$b.background-color, notbackground-color-color.You need to pad the hex colors with zeroes when they’re under 16 (
10hex). Easiest way to do this is: