2

Hello all I am working in JavaScript and want to generate colors for my graph.And I want a new color for every line and also the color should be light in shade.

I have read about question of color generation in java script

Random color generator in JavaScript

As I want new color for my line so random number generation will not work in my case Also the color should be light

I have read about the colors RGB values but I didn't find them following any pattern as how to choose light color

So any one can please guide me as is there a way to generate colors in sequence (avoid random) and choose only light color or any other function to make dark color lighter

Thanks

http://cloford.com/resources/colours/500col.htm

Community
  • 1
  • 1
A_user
  • 2,087
  • 6
  • 25
  • 33
  • 3
    You should use HSL color (google for it) in order to be able to define easily light or dark colors. It's [available in HTML5](https://www.google.com/?q=html5+hsl). – Denys Séguret Jun 27 '12 at 11:23

1 Answers1

10

You can try this way:

var new_light_color = 'rgb(' + (Math.floor((256-229)*Math.random()) + 230) + ',' + 
                                    (Math.floor((256-229)*Math.random()) + 230) + ',' + 
                                    (Math.floor((256-229)*Math.random()) + 230) + ')';

This way you generate colors that have red, green and blue in the range 230 - 256, which is a light color. You can go lower by changing the numbers, for darker colors.

Angel
  • 1,180
  • 9
  • 13
  • 1
    @A_user depending on the browser you have to support you could use a color space different from `rgb`: `hsl` it has an extra channel "lightness". more info: http://www.w3.org/TR/css3-color/#hsl-color It's supported in all major browsers and IE9 – Christoph Jun 27 '12 at 12:02
  • Well, hsl and hsla can be generated randomly similar to what I said above. – Angel Jun 27 '12 at 12:37