Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate light colour shades in javascript

Tags:

javascript

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

like image 899
A_user Avatar asked Nov 29 '25 04:11

A_user


1 Answers

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.

like image 99
Angel Avatar answered Dec 01 '25 17:12

Angel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!