Created
January 6, 2022 12:36
-
-
Save Just1B/16a5e78e8b519365ae79ca1acca58a9e to your computer and use it in GitHub Desktop.
Revisions
-
Just1B created this gist
Jan 6, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ function ColorToHex(color) { const hexadecimal = color.toString(16) return hexadecimal.length === 1 ? "0" + hexadecimal : hexadecimal } const items = [ "cold", "semi-cold", "ok", "hot", "very_hot" ] const items_colors = [] let alpha = 0.0 const step = 1 / items.length items.map( (item) => { alpha += step; // color_start = "#4cc9f0" -> rgb(76,201,240) // color_end = "#f72585" -> rgb(247,37,133) // if you have a lot of items -> color palette must have a good diff between channels // color_gradient_canal = min_channel_value * alpha + (1 - alpha) * max_channel_value const r = parseInt(76 * alpha + (1 - alpha) * 247); const g = parseInt(37 * alpha + (1 - alpha) * 201); const b = parseInt(133 * alpha + (1 - alpha) * 240); const hex = "#" + ColorToHex(r) + ColorToHex(g) + ColorToHex(b) items_colors.push({"color" : item, "color_hex": hex}) }) console.log(items_colors)