Reputation: 4226
Consider the "cols" is the number of distinguished colors in each row and the "rows" is the number of distinguished colors in each column for an area with the width of "w" and height of "h" how can I paint an uniform color palette like the following one? In fact, I'm looking for the algorithm to generate the RGB numbers.
Upvotes: 0
Views: 368
Reputation: 11522
To do this you have to calculate the HSB values first, then convert them to RGB afterwards. In HSB there are 256 different hues (colors), so you can support up to 256 different cells. The image you show is 8x64 cells = 512 different colors, so you will have to use two levels of brightness or saturation as well.
Upvotes: 0
Reputation: 21863
Looks like R * (255-x) + G * x + B * y
to me, with x
and y
between 0 and 255.
Each point's color is [255-x, x, y]
where x
and y
are its coordinates in a block [0, 255]^2
Upvotes: 2
Reputation: 5799
I would recommend having a look in the imagemagick library, which is capable of drawing pictures in a lot of languages.
Generating the RGB-numbers is nothing more than having three nested loops running from 0 to 255 or having one loop running through 2^24 and using modulo operations to separate the R, G and B values from it like so:
<?php
for ($i=0; $i<16777216; $i++) {
$r = ($i >> 16) % 256;
$g = ($i >> 8) % 256;
$b = $i % 256;
print("$i\t$r\t$g\t$b\n");
}
?>
Upvotes: 0