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