If I start with the array of hexadecimal colors
['#1147FF', '#86D8FF', '#FFEF67', '#FF7D11', '#F30000']
in JavaScript, I can achieve the color scale I desire by adjusting the steps on the scales website from 5 to 17. This simplifies the process as I can use 6-hex hex values.
Currently, my method involves converting hex values to RGB values and then iterating through them in a cumbersome manner. Here is a snippet of what I'm doing, disregarding the `green` variables:
green0pct = { r: 17, g: 71, b: 255 };
green7p5pct = { r: 134, g: 216, b: 255 };
green15pct = { r: 252, g: 233, b: 70 };
green22p5pct = { r: 255, g: 125, b: 17 };
green30pct = { r: 243, g: 0, b: 0 };
for (let j = 0; j <= 30; j++) {
if (j % 2 === 0) {
if (j < 7.5) {
newR = green0pct.r - (j * (green0pct.r - green7p5pct.r) / 7.5);//
newG = green0pct.g - (j * (green0pct.g - green7p5pct.g) / 7.5);
newB = green0pct.b - (j * (green0pct.b - green7p5pct.b) / 7.5);
} else if (j < 15) {
newR = green7p5pct.r - ((j - 7.5) * (green7p5pct.r - green15pct.r) / 7.5);
newG = green7p5pct.g - ((j - 7.5) * (green7p5pct.g - green15pct.g) / 7.5);
newB = green7p5pct.b - ((j - 7.5) * (green7p5pct.b - green15pct.b) / 7.5);
} else if (j < 22.5) {
newR = green15pct.r - ((j - 15) * (green15pct.r - green22p5pct.r) / 7.5);
newG = green15pct.g - ((j - 15) * (green15pct.g - green22p5pct.g) / 7.5);
newB = green15pct.b - ((j - 15) * (green15pct.b - green22p5pct.b) / 7.5);
} else {
newR = green22p5pct.r - ((j - 22.5) * (green22p5pct.r - green30pct.r) / 7.5);
newG = green22p5pct.g - ((j - 22.5) * (green22p5pct.g - green30pct.g) / 7.5);
newB = green22p5pct.b - ((j - 22.5) * (green22p5pct.b - green30pct.b) / 7.5);
}
displayPct = playerOrTeam === 'Team' ? (j - 15) / 2 : j - 15;
greenScale.push({ text: `${displayPct}%`, col: `rgb(${newR},${newG},${newB})` });
}}