hsl code for those tools

This commit is contained in:
Laetitia (O-01-67) 2022-11-14 11:21:15 -05:00 committed by GitHub
parent 9b0070eb45
commit 4f1def8d33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 60 additions and 6 deletions

View File

@ -864,15 +864,22 @@
color.s -= saturationChange;
break;
case "*":
case "x":
case "×":
case "multiply":
color.s *= saturationChange;
break;
case "/":
case "÷":
case "divide":
color.s /= saturationChange;
break;
case "=":
case "set":
color.s = saturationChange;
break;
default:
throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", or \"divide\"");
throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", \"divide\", or \"set\"");
};
color.h = Math.round(color.h % 360);
@ -890,22 +897,69 @@
switch(operationType.toLowerCase()) {
case "+":
case "add":
color.s += luminanceChange;
color.l += luminanceChange;
break;
case "-":
case "subtract":
color.s -= luminanceChange;
color.l -= luminanceChange;
break;
case "*":
case "x":
case "×":
case "multiply":
color.s *= luminanceChange;
color.l *= luminanceChange;
break;
case "/":
case "÷":
case "divide":
color.s /= luminanceChange;
color.l /= luminanceChange;
break;
case "=":
case "set":
color.l = luminanceChange;
break;
default:
throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", or \"divide\"");
throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", \"divide\", or \"set\"");
};
color.h = Math.round(color.h % 360);
color.s = Math.round(bound(color.s,0,100));
color.l = Math.round(bound(color.l,0,100));
return convertHslObjects(color,outputType);
};
function changeHue(color,hueChange,operationType="add",outputType="rgb",arrayType=null) {
color = normalizeColorToHslObject(color,arrayType);
//only {h,s,l} should exist now
//Math
switch(operationType.toLowerCase()) {
case "+":
case "add":
color.h += hueChange;
break;
case "-":
case "subtract":
color.h -= hueChange;
break;
case "*":
case "x":
case "×":
case "multiply":
color.h *= hueChange;
break;
case "/":
case "÷":
case "divide":
color.h /= hueChange;
break;
case "=":
case "set":
color.h = hueChange;
break;
default:
throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", \"divide\", or \"set\"");
};
color.h = Math.round(color.h % 360);