From 99519b05d12ca04a789dba503d01fcd37dd03535 Mon Sep 17 00:00:00 2001 From: "Laetitia (O-01-67)" <68935009+O-01-67@users.noreply.github.com> Date: Tue, 24 Jan 2023 13:39:51 -0500 Subject: [PATCH] mv func in --- mods/code_library.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mods/code_library.js b/mods/code_library.js index 90dc00e7..885ed8f2 100644 --- a/mods/code_library.js +++ b/mods/code_library.js @@ -592,8 +592,10 @@ return convertColorFormats(color,"rgb"); }; - function averageColorObjects(color1,color2,weight1=0.5) { /*third argument is for color1 and expects a float from 0 - to 1, where 0 means "all color2" and 1 means "all color1"*/ + + function averageColorObjects(color1,color2,weight1=0.5) { //misnomer, actually a linear interpolation but it's too late to rename that + //third argument is for color1 and expects a float from 0 to 1, where 0 means "all color2" and 1 means "all color1" + //(backwards from how it should work) var w1 = Math.min(Math.max(weight1,0),1) var red1 = color1.r var green1 = color1.g @@ -607,6 +609,13 @@ return {r: red3, g: green3, b: blue3} }; + function lerpColors(color1,color2,outputType="rgb",weight1=0.5) { + color1 = convertColorFormats(color1,"json"); + color2 = convertColorFormats(color2,"json"); + theColor = averageColorObjects(color1,color2,weight1); + return convertColorFormats(theColor,outputType); + }; + function multiplyColors(color1,color2,outputType="rgb") { //normalize rgb()/hex by turning any hex into rgb() and then rgb()s to {r,g,b} if(typeof(color1) !== "object") {