generate random hsl color values

Solutions on MaxInterview for generate random hsl color values by the best coders in the world

showing results for - "generate random hsl color values"
Agathe
22 Jan 2020
1function makeColor(colorNum, colors){
2    if (colors < 1) colors = 1;
3    // defaults to one color - avoid divide by zero
4    return colorNum * (360 / colors) % 360;
5}
6// This could be length of your array.
7var totalDIVs = 20;
8var totalColors = totalDIVs;
9
10for (var i = 0; i < totalDIVs; i++){
11    var element = document.createElement('div');
12    document.body.appendChild(element);
13    var color = "hsl( " + makeColor(i, totalColors) + ", 100%, 50% )";
14    element.style.backgroundColor = color;
15    element.innerHTML = color;
16}