From e86e9240b8e277cf7c2a0914b930a71aefa37288 Mon Sep 17 00:00:00 2001 From: "Laetitia (O-01-67)" <68935009+O-01-67@users.noreply.github.com> Date: Tue, 22 Nov 2022 20:15:48 -0500 Subject: [PATCH] min and max logic --- mods/code_library.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/mods/code_library.js b/mods/code_library.js index 6cb305ae..183e0fb4 100644 --- a/mods/code_library.js +++ b/mods/code_library.js @@ -878,8 +878,18 @@ case "set": color.s = saturationChange; break; + case ">": + case ">=": + case "min": //lower-bounds the color + color.s = Math.max(color.s,saturationChange); //math.max to bound it to the higher of the input number or the existing color + break; + case "<": + case "<=": + case "max": //upper-bounds the color + color.s = Math.min(color.s,saturationChange); //math.min to bound it to the lower of the input number or the existing color + break; default: - throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", \"divide\", or \"set\""); + throw new Error("Operation must be \"add\", \"subtract\", \"multiply\", \"divide\", \"set\", \"min\", or \"max\""); }; color.h = Math.round(color.h % 360); @@ -918,8 +928,18 @@ case "set": color.l = luminanceChange; break; + case ">": + case ">=": + case "min": + color.l = Math.max(color.l,luminanceChange); + break; + case "<": + case "<=": + case "max": + color.l = Math.min(color.l,luminanceChange); + break; default: - throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", \"divide\", or \"set\""); + throw new Error("Operation must be \"add\", \"subtract\", \"multiply\", \"divide\", \"set\", \"min\", or \"max\""); }; color.h = Math.round(color.h % 360); @@ -958,8 +978,18 @@ case "set": color.h = hueChange; break; + case ">": + case ">=": + case "min": + color.h = Math.max(color.h,hueChange); + break; + case "<": + case "<=": + case "max": + color.h = Math.min(color.h,hueChange); + break; default: - throw new Error("operationType must be \"add\", \"subtract\", \"multiply\", \"divide\", or \"set\""); + throw new Error("Operation must be \"add\", \"subtract\", \"multiply\", \"divide\", \"set\", \"min\", or \"max\""); }; color.h = Math.round(color.h % 360);