[thelist] How to Make a Set of Different Random Colors

Fred Jones fredthejonester at gmail.com
Thu Aug 14 06:41:09 CDT 2008


I am making charts on the fly but all data is dynamic, including the
number of elements. How can I generate nice colors so that each slice
of the pie chart will be a different, unique, yet BRIGHT color? I am
using this now:

toColor(167772/$index_num);

which takes 167772 and divides it by the index of the slice of the
pie, which will be 1,2,3,4 etc. until the last slice, which may be 13,
maybe a bit more.

That magic number I chose at random--I actually used the decimal for
FFFFFF and then just removed digits off the right side until the
colors look OK, but they are all presently blue and green. I
understand the reason for this, but I don't have a better idea just
yet.

I tried approaching the R, G and B individually and used
255/$index_num for R and then 255-(255/$index_num) for G and then
124+(255/$dao->value) for B, but this is even worse. :(

Anyone who understands colors a bit more have any better suggestions?

Thanks!



More information about the thelist mailing list