short shmort
This commit is contained in:
parent
04ad311289
commit
f5ed9d0c64
|
@ -11,19 +11,19 @@ const batteryIcon = batteryPercent => ({
|
||||||
const hex2rgb = (hex, h = hex.replace('#', '0x')) => ({ r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 });
|
const hex2rgb = (hex, h = hex.replace('#', '0x')) => ({ r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 });
|
||||||
const rgb2Hex = rgb => "#" + ((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1);
|
const rgb2Hex = rgb => "#" + ((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1);
|
||||||
|
|
||||||
const interpolateColor = (ff, c) => {
|
const interpolateColor = (f, c) => {
|
||||||
if(!ff) return "transparent";
|
if(!f) return "transparent";
|
||||||
if(ff >= 1) return c.pop();
|
if(f >= 1) return c.pop();
|
||||||
if(ff <= 0) return c[0];
|
if(f <= 0) return c[0];
|
||||||
|
|
||||||
let f = ff * (c.length - 1);
|
f *= c.length - 1;
|
||||||
const i = ~~f;
|
const i = ~~f;
|
||||||
f -= i;
|
f -= i;
|
||||||
const [ c1, c2 ] = [ hex2rgb(c[i]), hex2rgb(c[i + 1]) ];
|
const [ c1, c2 ] = [ hex2rgb(c[i]), hex2rgb(c[i + 1]) ];
|
||||||
|
|
||||||
return rgb2Hex({
|
return rgb2Hex({
|
||||||
r: parseInt(~~(c1.r + ((c2.r - c1.r) * f)), 10),
|
r: c1.r + ((c2.r - c1.r) * f) | 10,
|
||||||
g: parseInt(~~(c1.g + ((c2.g - c1.g) * f)), 10),
|
g: c1.g + ((c2.g - c1.g) * f) | 10,
|
||||||
b: parseInt(~~(c1.b + ((c2.b - c1.b) * f)), 10)
|
b: c1.b + ((c2.b - c1.b) * f) | 10
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user