'Create color palette from color
I have elements that should be colored by some color. However the bigger index of the element the 'lighter' shade of said color it should be, but never gray or white.
What is some function to achieve this? The only thing i have found is
const adjust = (color, amount) => {
return '#' + color.replace(/^#/, '').replace(/../g, color => ('0' + Math.min(255, Math.max(0, parseInt(color, 16) + amount)).toString(16)).substr(-2));
}
function, but it always results in grey and even white color.
e.g:
let elements = fetchElements(); // approx 300 elements
for( let i = 0 ; i < elements.length ;i++ ){
let color = adjust(#000000,i);
buildElement( elements[i]; color );
}
Solution 1:[1]
I don't realy undrestand what you are doing here(!) but maybe you could use RGBA format, lower the alpha number on each loop then convert it back to hex.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shahryar_Jahanshahloo |
