I want to create an array of colors in javascript, for that, I used the js file rainbowvis.js here, I have 100 colors, but they are not really distinct.
I should be able to see the difference because I will use this table to a chart.
Is it possible with rainbowvis.js or is there an other solution?
style. backgroundColor = 'rgb('+ rgb. join(',') +')'; If you want to constrict it to known colors, you can create an array of the colors and randomly select it like so.
To define the color or shading of object displayed on screen or printed on paper, color values are used, which are typically based on color models. Models may include a single color (such as for the grayscale model) or multiple colors.
The separation of visible light into its different colors is known as dispersion. Each color is characteristic of a distinct wavelength; and different wavelengths of light waves will bend varying amounts upon passage through a prism.
To generate 100 colors (each color from 1 to 1000000 - change it if you need other range):
var colors = [];
while (colors.length < 100) {
do {
var color = Math.floor((Math.random()*1000000)+1);
} while (colors.indexOf(color) >= 0);
colors.push("#" + ("000000" + color.toString(16)).slice(-6));
}
console.log(colors);
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With