From 9b0070eb45baa3f0ef24081cf19de55bb5166437 Mon Sep 17 00:00:00 2001 From: "Laetitia (O-01-67)" <68935009+O-01-67@users.noreply.github.com> Date: Mon, 14 Nov 2022 11:20:43 -0500 Subject: [PATCH] hsl tools --- mods/color_tools.js | 160 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 2 deletions(-) diff --git a/mods/color_tools.js b/mods/color_tools.js index 378802d3..521ed8c5 100644 --- a/mods/color_tools.js +++ b/mods/color_tools.js @@ -3,14 +3,120 @@ var libraryMod = "mods/code_library.js"; if(enabledMods.includes(libraryMod)) { var colorToolCounter = 0; + var saturationAmount = 1; + var saturationOp = "add"; + var luminanceAmount = 1; + var luminanceOp = "add"; + var hueAmount = 1; + var hueOp = "add"; - function colorToolCounterIncrement() { + var ops = ["add","subtract","multiply","divide","set","+","-","*","x","×","/","÷","="]; + + function saturationPrompt() { + var preSaturation = prompt("Enter the value you want to use"); + var preSatOp = prompt(`Enter the operation ("add", "subtract", "multiply", or "divide", or "set")`); + + //value check + if(isNaN(parseFloat(preSaturation))) { + if(preSaturation === "" || preSaturation === null) { + alert("No value was specified! Defaulting to 1"); + preSaturation = 1; + } else { + alert("Invalid value! The value must be a number (defaulting to 1)"); + preSaturation = 1; + }; + }; + preSaturation = parseFloat(preSaturation); + + //operation check + if(!ops.includes(preSatOp.toLowerCase())) { + if(preSatOp === "" || preSatOp === null) { + alert(`No operation was specified! Defaulting to "add".`); + preSatOp = "add"; + } else { + alert(`Invalid operation! Only "add", "subract", "multiply", "divide", and "set" are accepted (defaulting to "add").`); + preSatOp = "add"; + }; + }; + + saturationAmount = preSaturation; + saturationOp = preSatOp; + return [preSaturation, preSatOp]; + }; + + function luminancePrompt() { + var preLuminance = prompt("Enter the value you want to use"); + var preLumOp = prompt(`Enter the operation ("add", "subtract", "multiply", or "divide", or "set")`); + + //value check + if(isNaN(parseFloat(preLuminance))) { + if(preLuminance === "" || preLuminance === null) { + alert("No value was specified! Defaulting to 1"); + preLuminance = 1; + } else { + alert("Invalid value! The value must be a number (defaulting to 1)"); + preLuminance = 1; + }; + }; + + //operation check + if(!ops.includes(preLumOp.toLowerCase())) { + if(preLumOp === "" || preLumOp === null) { + alert(`No operation was specified! Defaulting to "add".`); + preLumOp = "add"; + } else { + alert(`Invalid operation! Only "add", "subract", "multiply", "divide", and "set" are accepted (defaulting to "add").`); + preLumOp = "add"; + }; + }; + preLuminance = parseFloat(preLuminance) + + luminanceAmount = preLuminance; + luminanceOp = preLumOp; + return [preLuminance, preLumOp]; + }; + + function huePrompt() { + var preHue = prompt("Enter the value you want to use"); + var preHueOp = prompt(`Enter the operation ("add", "subtract", "multiply", or "divide", or "set")`); + + //value check + if(isNaN(parseFloat(preHue))) { + if(preHue === "" || preHue === null) { + alert("No value was specified! Defaulting to 1"); + preHue = 1; + } else { + alert("Invalid value! The value must be a number (defaulting to 1)"); + preHue = 1; + }; + }; + + preHue = parseFloat(preHue); + + //operation check + if(!ops.includes(preHueOp.toLowerCase())) { + if(preHueOp === "" || preHueOp === null) { + alert(`No operation was specified! Defaulting to "add".`); + preHueOp = "add"; + } else { + alert(`Invalid operation! Only "add", "subract", "multiply", "divide", and "set" are accepted (defaulting to "add").`); + preHueOp = "add"; + }; + }; + + hueAmount = preHue; + hueOp = preHueOp; + return [preHue, preHueOp]; + }; + + /*function colorToolCounterIncrement() { if(typeof(colorToolCounter) === "undefined") { colorToolCounter = 0; }; colorToolCounter++; }; - colorToolCounterInterval = setInterval(colorToolCounterIncrement, 50); + colorToolCounterInterval = setInterval(colorToolCounterIncrement, 50);*/ + colorToolCounterInterval = 0; elements.multiply_color = { color: ["#c27070","#c29c70","#c2c270","#70c270","#70c2c2","#7070c2","#c270c2"], @@ -21,6 +127,7 @@ if(enabledMods.includes(libraryMod)) { }; }, customColor: true, + cooldown: 3, category: "color tools", //the toolbar is getting cluttered excludeRandom: true, //the toolbar is getting cluttered } @@ -34,6 +141,7 @@ if(enabledMods.includes(libraryMod)) { }; }, customColor: true, + cooldown: 3, category: "color tools", excludeRandom: true, } @@ -47,6 +155,7 @@ if(enabledMods.includes(libraryMod)) { }; }, customColor: true, + cooldown: 3, category: "color tools", excludeRandom: true, } @@ -60,10 +169,53 @@ if(enabledMods.includes(libraryMod)) { }; }, customColor: true, + cooldown: 3, category: "color tools", excludeRandom: true, } + elements.hue = { + color: ["#ff0000","#ccff00","#00ff66","#0066ff","#cc00ff","#ff0000"], + tool: function(pixel) { + if(colorToolCounter % 3 == 0) { + pixel.color = changeHue(pixel.color,hueAmount,hueOp,"rgb"); + colorToolCounter = 0; + }; + }, + cooldown: 3, + category: "color tools", + excludeRandom: true, + desc: "Click here to configure the tool." + } + + elements.saturation = { + color: ["#808080","#996666","#b34d4d","#cc3333","#e61919","#ff0000"], + tool: function(pixel) { + if(colorToolCounter % 3 == 0) { + pixel.color = changeSaturation(pixel.color,saturationAmount,saturationOp,"rgb"); + colorToolCounter = 0; + }; + }, + cooldown: 3, + category: "color tools", + excludeRandom: true, + desc: "Click here to configure the tool." + } + + elements.luminance = { + color: ["#000000","#333333","#666666","#999999","#cccccc","#ffffff"], + tool: function(pixel) { + if(colorToolCounter % 3 == 0) { + pixel.color = changeLuminance(pixel.color,luminanceAmount,luminanceOp,"rgb"); + colorToolCounter = 0; + }; + }, + cooldown: 3, + category: "color tools", + excludeRandom: true, + desc: "Click here to configure the tool." + } + elements.grayscale = { color: ["#7f7f7f"], tool: function(pixel) { @@ -73,6 +225,7 @@ if(enabledMods.includes(libraryMod)) { var finalColor = [lightness, lightness, lightness] pixel.color = "rgb(" + finalColor.join(",") + ")" }, + cooldown: 3, category: "color tools", excludeRandom: true, } @@ -88,6 +241,7 @@ if(enabledMods.includes(libraryMod)) { colorToolCounter = 0; }; }, + cooldown: 3, category: "color tools", excludeRandom: true, } @@ -103,6 +257,7 @@ if(enabledMods.includes(libraryMod)) { colorToolCounter = 0; }; }, + cooldown: 3, category: "color tools", excludeRandom: true, } @@ -118,6 +273,7 @@ if(enabledMods.includes(libraryMod)) { colorToolCounter = 0; }; }, + cooldown: 3, category: "color tools", excludeRandom: true, }