Skip to content

Commit

Permalink
Refactor color calculation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Anto426 committed Oct 9, 2024
1 parent 572f8bf commit 31d972b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function rgbToHsl(r, g, b) {
let h, s, l = (max + min) / 2;

if (max === min) {
h = s = 0; // È un grigio
h = s = 0;
} else {
const d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
Expand All @@ -166,16 +166,14 @@ function rgbToHsl(r, g, b) {
h /= 6;
}

return [h, s, l]; // h è la tonalità (hue)
return [h, s, l];
}



function colorDistance(color1, color2) {
const rDiff = color1[0] - color2[0];
const gDiff = color1[1] - color2[1];
const bDiff = color1[2] - color2[2];
return Math.sqrt(rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
let difRgb = diffColor(color1, color2);
return Math.sqrt(Math.pow(difRgb[0], 2) + Math.pow(difRgb[1], 2) + Math.pow(difRgb[2], 2));
}


Expand All @@ -187,11 +185,6 @@ function diffColor(color,color2) {
return [rDiff, gDiff, bDiff];
}

function colormedia(color1, color2) {
let difRgb = diffColor(color1, color2);
return Math.sqrt(Math.pow(difRgb[0], 2) + Math.pow(difRgb[1], 2) + Math.pow(difRgb[2], 2));
}

function ArrayToRgb(color) {
return `rgb(${color[0]}, ${color[1]}, ${color[2]})`
}
Expand Down

0 comments on commit 31d972b

Please sign in to comment.