From eae959e43d87a354b4812d5bbf7911ef4d4ff4d7 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername Date: Mon, 8 Jan 2024 17:18:58 -0500 Subject: [PATCH] the dyer --- mods/nousersthings.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/mods/nousersthings.js b/mods/nousersthings.js index f1260abf..e1c8558e 100644 --- a/mods/nousersthings.js +++ b/mods/nousersthings.js @@ -1970,4 +1970,37 @@ elements.gas_filter = { canContain: true, noMix: true, } - +function weightedAverage(num1, num2, weight){ + return ((weight * num1)+((1-weight)*num2)) +} +elements.dyer = { + customColor: true, + color: ["#ff0000","#ff8800","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff"], + behavior: behaviors.wall, + movable: false, + state: "solid", + category: "machines", + tick: function(pixel){ + for (var i = 0; i < squareCoordsShuffle.length; i++) { + var coord = squareCoordsShuffle[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true)) { + if (!(pixelMap[x][y].element == "dyer")){ + var newPixel = pixelMap[x][y]; + var rgb1 = pixel.color.match(/\d+/g); + var rgb2 = newPixel.color.match(/\d+/g); + // average the colors + var rgb = [ + weightedAverage(parseInt(rgb1[0]), parseInt(rgb2[0]), 0.2), + weightedAverage(parseInt(rgb1[1]), parseInt(rgb2[1]), 0.2), + weightedAverage(parseInt(rgb1[2]), parseInt(rgb2[2]), 0.2), + ]; + // convert rgb to hex + var hex = RGBToHex(rgb); + newPixel.color = pixelColorPick(newPixel, hex); + } + } + } + } +} \ No newline at end of file