19 May 2010

Javascript Color scaling

Over the last weekend, I have been working on a script to apply a color gradient to number of rows in a HTML table. I wanted a gradient from green to red.

In HTML, color is determined by the R, G & B values. Hence logically, I should start with Red (#FFOOOO). reduce red to white (#OOOOOO). Then I can increase green slowly to achieve complete green (#OOFFOO). Surprisingly this logic does not work! There are different shades but not a continuous gradient.

To achieve a gradient, you have to go to a common color. So the color gradation should go from Red (#FFOOOO) to Yellow (#FFFFOO) then to green (#OOFFOO).

For the exact javascript, feel free to reach out to me.

No comments:

Post a Comment