Skip to content

Commit 3c82322

Browse files
committed
fix
1 parent 4e7079e commit 3c82322

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

main.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
// Function to convert hex to RGB
12
function hexToRgb(hex) {
2-
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
3-
return result
4-
? {
5-
r: parseInt(result[1], 16),
6-
g: parseInt(result[2], 16),
7-
b: parseInt(result[3], 16),
8-
}
9-
: null;
3+
hex = hex.replace("#", "");
4+
const bigint = parseInt(hex, 16);
5+
const r = (bigint >> 16) & 255;
6+
const g = (bigint >> 8) & 255;
7+
const b = bigint & 255;
8+
return [r, g, b];
109
}
1110

11+
// Function to convert RGB to hex
1212
function rgbToHex(r, g, b) {
13-
return (
14-
"#" +
15-
((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase()
16-
);
13+
return `#${((1 << 24) + (r << 16) + (g << 8) + b)
14+
.toString(16)
15+
.slice(1)
16+
.toUpperCase()}`;
1717
}
1818

19-
function interpolateColor(startRgb, endRgb, factor) {
20-
return {
21-
r: Math.round(startRgb.r + factor * (endRgb.r - startRgb.r)),
22-
g: Math.round(startRgb.g + factor * (endRgb.g - startRgb.g)),
23-
b: Math.round(startRgb.b + factor * (endRgb.b - startRgb.b)),
24-
};
19+
// Function to interpolate between two colors
20+
function interpolateColor(color1, color2, factor) {
21+
const result = color1.slice();
22+
for (let i = 0; i < 3; i++) {
23+
result[i] = Math.round(result[i] + factor * (color2[i] - result[i]));
24+
}
25+
return result;
2526
}
2627

2728
// Function to generate the gradient

0 commit comments

Comments
 (0)