This commit is contained in:
David Ralph
2021-01-16 22:43:46 +00:00
parent 0a735384df
commit 3ec5a2c199
32 changed files with 530 additions and 182 deletions

View File

@@ -9,8 +9,13 @@ export default function hexToRgb(value) {
const valid = hexRegexp.test(value);
if (valid) {
if (value[0] === '#') value = value.slice(1, value.length);
if (value.length === 3) value = value.replace(regexp, '$1$1$2$2$3$3');
if (value[0] === '#') {
value = value.slice(1, value.length);
}
if (value.length === 3){
value = value.replace(regexp, '$1$1$2$2$3$3');
}
const red = parseInt(value.substr(0, 2), 16);
const green = parseInt(value.substr(2, 2), 16);

View File

@@ -3,9 +3,17 @@ export default function rgbToHex(red, green, blue) {
let g16 = green.toString(16);
let b16 = blue.toString(16);
if (red < 16) r16 = `0${r16}`;
if (green < 16) g16 = `0${g16}`;
if (blue < 16) b16 = `0${b16}`;
if (red < 16) {
r16 = `0${r16}`;
}
if (green < 16) {
g16 = `0${g16}`;
}
if (blue < 16) {
b16 = `0${b16}`;
}
return r16 + g16 + b16;
}

View File

@@ -18,11 +18,19 @@ export default function rgbToHSv({ red, green, blue }) {
gg = diffc(gabs);
bb = diffc(babs);
if (rabs === v) h = bb - gg;
else if (gabs === v) h = (1 / 3) + rr - bb;
else if (babs === v) h = (2 / 3) + gg - rr;
if (h < 0) h += 1;
else if (h > 1) h -= 1;
if (rabs === v){
h = bb - gg;
} else if (gabs === v) {
h = (1 / 3) + rr - bb;
} else if (babs === v) {
h = (2 / 3) + gg - rr;
}
if (h < 0) {
h += 1;
} else if (h > 1) {
h -= 1;
}
}
return {

View File

@@ -10,8 +10,10 @@ export default function setRGBA(red, green, blue, alpha) {
blue: blue | 0,
};
if (isValidRGBValue(alpha) === true) color.alpha = alpha | 0;
// RGBToHSL(color.r, color.g, color.b);
if (isValidRGBValue(alpha) === true) {
color.alpha = alpha | 0;
}
return color;
}
}