From d92a65d7db381ca415bad1117d94f79089c16bc3 Mon Sep 17 00:00:00 2001 From: "Laetitia (O-01-67)" <68935009+O-01-67@users.noreply.github.com> Date: Thu, 29 Dec 2022 21:54:30 -0500 Subject: [PATCH] simple stripe paint to do: configurable tightness, phase, and angle (would require difficult code rework and weird math shit i don't know); hsl support to recolor after-the-fact, you have to set oldColor instead of the paint tool (doable through mouse with prop.js, but you have to triple-check because it will not handle rgb() errors) --- mods/stripe_paint.js | 120 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 mods/stripe_paint.js diff --git a/mods/stripe_paint.js b/mods/stripe_paint.js new file mode 100644 index 00000000..f8af6f0c --- /dev/null +++ b/mods/stripe_paint.js @@ -0,0 +1,120 @@ +function averageColors(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 stripeFunction(pixel,sineParamFunction) { + if(pixel.oldColor == undefined || pixel.oldColor == null) { + pixel.oldColor = pixel.color; + }; + + //oldColor self staining + for (var i = 0; i < adjacentCoords.length; i++) { + var x = pixel.x+adjacentCoords[i][0]; + var y = pixel.y+adjacentCoords[i][1]; + if(isEmpty(x,y,true)) { + continue; + }; + var otherPixel = pixelMap[x][y]; + if(otherPixel.element == pixel.element && pixel.oldColor && otherPixel.oldColor) { + otherPixel.oldColor = averageColors(pixel.oldColor,otherPixel.oldColor); + }; + }; + + var sineWeight = (1+Math.sin(sineParamFunction(pixel)))/2; + var preColor = averageColors(pixel.oldColor,"rgb(0,0,0)","json",sineWeight); + for(colorlet in preColor) { + preColor[colorlet] = Math.round(preColor[colorlet]); + }; + pixel.color = convertColorFormats(preColor,"rgb"); +}; + +function horizontalSpf(pixel) { + return pixel.y; +}; + +function verticalSpf(pixel) { + return pixel.x; +}; + +function diagonalSpf(pixel) { + return pixel.x+pixel.y; +}; + +function diagonalAltSpf(pixel) { + return pixel.x-pixel.y; +}; + +elements.horizontal_stripe_paint = { + behavior: behaviors.LIQUID, + state: "liquid", + density: 998, + tempHigh: 100, + stateHigh: "smoke", + color: elements.paint.color, + customColor: true, + category: "stripe paint", + properties: { + oldColor: null + }, + stain: elements.dye.stain, + tick: function(pixel) { + stripeFunction(pixel,horizontalSpf); + }, +}; + +elements.vertical_stripe_paint = { + behavior: behaviors.LIQUID, + state: "liquid", + density: 998, + tempHigh: 100, + stateHigh: "smoke", + color: elements.paint.color, + customColor: true, + category: "stripe paint", + properties: { + oldColor: null + }, + stain: elements.dye.stain, + tick: function(pixel) { + stripeFunction(pixel,verticalSpf); + }, +}; + +elements.diagonal_stripe_paint = { + behavior: behaviors.LIQUID, + state: "liquid", + density: 998, + tempHigh: 100, + stateHigh: "smoke", + color: elements.paint.color, + customColor: true, + category: "stripe paint", + properties: { + oldColor: null + }, + stain: elements.dye.stain, + tick: function(pixel) { + stripeFunction(pixel,diagonalSpf); + }, +}; + +elements.diagonal_2_stripe_paint = { + behavior: behaviors.LIQUID, + state: "liquid", + density: 998, + tempHigh: 100, + stateHigh: "smoke", + color: elements.paint.color, + customColor: true, + category: "stripe paint", + properties: { + oldColor: null + }, + stain: elements.dye.stain, + tick: function(pixel) { + stripeFunction(pixel,diagonalAltSpf); + }, +}; \ No newline at end of file