I am trying to generate random color codes or one base colour-based codes. I am not much familiar with JavaScript & coloring
What I have gathered so far:
function getColors(len) {
var colors = [];
for (var i = 0; i < len; i++) {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
colors.push(color);
}
return colors;
}
Thanks
If i understood you correctly. Try below function. It returns you the collection of colors if you pass anything and random. But if you pass
baseColorit will generatehueset of colors based onbasedColor.huedefined base colors are :red,yellow,green,cyan,blue&magenta.Usage
example: 1 -
getRandomColors(10)orgetRandomColors(10,'random')orgetRandomColors(10,'anything besides Hue')result :
//(10) ["#C4AD05", "#B63DCB", "#22A9FE", "#59DCAC", "#986FFD", "#493E56", "#49693D", "#83029A", "#59E3C0", "#C6FB84"]example: 2 -
getRandomColors(10,'blue') //baseColorresult:
//(10) ["hsl(240, 79%, 19%)", "hsl(240, 44%, 45%)", "hsl(240, 13%, 64%)", "hsl(240, 63%, 73%)", "hsl(240, 52%, 45%)", "hsl(240, 61%, 83%)", "hsl(240, 46%, 58%)", "hsl(240, 35%, 6%)", "hsl(240, 89%, 89%)", "hsl(240, 76%, 97%)"]Code