From 1b7f2d1004615252371e60459a66d5e629af5e2d Mon Sep 17 00:00:00 2001 From: O-01-67 <68935009+O-01-67@users.noreply.github.com> Date: Wed, 14 Sep 2022 14:44:56 -0400 Subject: [PATCH] new test ass --- mods/x_dependent_change_test.js | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 mods/x_dependent_change_test.js diff --git a/mods/x_dependent_change_test.js b/mods/x_dependent_change_test.js new file mode 100644 index 00000000..bf6a6244 --- /dev/null +++ b/mods/x_dependent_change_test.js @@ -0,0 +1,34 @@ +function randomOfTwo(option1,option2,leftChance=0.5) { + if(Math.random() < leftChance) { + return option1; + } else { + return option2; + }; +}; + +elements.xdct = { + name: "x-dependent change test", + color: "#cc33cc", + hardness: 0.5, + density: 2400, + behavior: behaviors.POWDER, + state: "solid", + category: "solids", + tick: function(pixel) { + var halfWidth = width / 2; + var halfHeight = height / 2; + var transitionLeftEdge = 4/5 * halfWidth; + var transitionRightEdge = 6/5 * halfWidth; + var x = pixel.x; + if(x < transitionLeftEdge) { //To the left + changePixel(pixel,"sand"); + } else if(x > transitionRightEdge) { //To the right + changePixel(pixel,"dirt"); + } else { //Other (e.g. equal to) + var distanceFromLeftEdge = x - transitionLeftEdge; + var distanceBetweenEdges = transitionRightEdge - transitionLeftEdge; + var relativePosition = distanceFromLeftEdge / distanceBetweenEdges; + changePixel(pixel,randomOfTwo("dirt","sand",relativePosition)); + }; + }, +}; \ No newline at end of file