Create Colors based on # of Items

Preferably using PHP, I’d like to create X number of colors based on X number of items and using a predefined color range. For example:

[table]
[tr]
[td]ITEM[/td]
[td]VALUE[/td]
[/tr]
[tr]
[td]1[/td]
[td]1,234,567,890[/td]
[/tr]
[tr]
[td]2[/td]
[td]234,567,890[/td]
[/tr]
[tr]
[td]3[/td]
[td]34,567,890[/td]
[/tr]
[tr]
[td]4[/td]
[td]4,567,890[/td]
[/tr]
[tr]
[td]5[/td]
[td]567,890[/td]
[/tr]
[/table]

Color Range
red = largest value
green = medium value
blue = smallest value

Example
Item 1 gets color red
Item 2 gets whatever color naturally comes between red and green
Item 3 gets color green
Item 4 gets whatever color naturally comes between green and blue
Item 5 gets color blue

Requirements
The code should be able to handle any number of items. 5 items was just an easy example.

Some Thoughts

  • Number of items = number of colors
  • How to divide a color range into number of items?
  • Colors can be represented in decimal format: red=255,000,000 blue=000,000,255
  • Can a formula be created, based on the color decimal format, to solve this problem?

I think it’s the math portion of the problem that I’m stuck on right now.
Thanks for your help,

Nick

Sponsor our Newsletter | Privacy Policy | Terms of Service