Dynamically Generate Pleasing Colors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm drawing a GD map from selected points in a database.

I am using imagecreatetruecolor.

I'm outputting PNGs, but could change to JPEG if it would help. [I doubt it]

In experimentation so far, I've found that using the lighter shades is
more pleasing to the eye, in general, so want to stay above 0x66 in R, G,
and B values.

The background will be white, so I can't get too close to that color either.

I'd like the colors to be not TOO ugly with each other, and I absolutely
cannot have the borders of two regions the exact SAME color.

Now, I don't want to get into Fermat's Last Theorom and 2 billion lines of
code to do the 4-color thing, so that's out.

And I'm not a Designer, so I have NO IDEA if there's some magical listing
of "pretty colors number 1 through N" that go together.  I'm still waiting
for "Geranimals for Men" to come out. :-)

I could just use $N colors, for however many colors I need, and not worry
about the borders at all.  The occasional case of two shades of green
being too close is "livable" though not "ideal"

I've tried your basic 3-D loop:
for ($r ...)
  for ($g ...)
    for ($b ...)
       $colors[] = imagecolorallocate($image, $r, $g, $b);
to generate the colors with acceptable ranges in values, skipping shades
of grey, or even any shades where $r == $g || $r == $b || $g == $b to try
to avoid same-looking colors.

I probably won't ever need more than 250 colors, really, so played around
with settings that seemed like they should work.

I used shuffle() sometimes to try and mix up the colors

I've had what you might call mixed results...

I've searched and read, and only vaguely understand the ideas behind
brightness and contrast in RGB number system, so can't figure out anything
useful from my findings of maximizing contrast of an existing image etc.

I'm not using php 5 yet, so imagefilter is "out"

I'm hoping somebody has gone through this already, and has an easy way to
generate a pleasing set of colors, with good contrast, for any given
number $N of colors.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux