From 1022dfc41cc3d07a6ec6a2188b626ef5da277f47 Mon Sep 17 00:00:00 2001 From: Lily-129 <68935009+Lily-129@users.noreply.github.com> Date: Tue, 1 Mar 2022 13:22:34 -0500 Subject: [PATCH] like circles but with triangles --- mods/acidtriangles.js | 127 ++++++++++++++++++++++++++++++++++++++++++ mods/triangles.js | 118 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 mods/acidtriangles.js create mode 100644 mods/triangles.js diff --git a/mods/acidtriangles.js b/mods/acidtriangles.js new file mode 100644 index 00000000..d57bd152 --- /dev/null +++ b/mods/acidtriangles.js @@ -0,0 +1,127 @@ +incrementt = 0; + +interval = setInterval( increment, 500/30); + +function increment(){ + incrementt = incrementt % (Math.PI*8.8) + (Math.PI/30); +} + +pixelSize = 30 + function drawPixels(forceTick=false) { + // newCurrentPixels = shuffled currentPixels + var newCurrentPixels = currentPixels.slice(); + var pixelsFirst = []; + var pixelsLast = []; + if (!paused || forceTick) { + shuffleArray(newCurrentPixels); + } + /*{newCurrentPixels.sort(function(p) { // shuffle the pixels but keep elements[p.element].isGas last + return 0.5 - Math.random(); + })} // shuffle the pixels if not paused*/ + for (var i = 0; i < newCurrentPixels.length; i++) { + pixel = newCurrentPixels[i]; + //if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue} + if (pixel.del) {continue} + if (!paused || forceTick) { + if (elements[pixel.element].tick) { // Run tick function if it exists + elements[pixel.element].tick(pixel); + } + if (pixel.del) {continue} + if (elements[pixel.element].behavior) { // Parse behavior if it exists + pixelTick(pixel); + } + }; + if (elements[pixel.element].isGas) { + pixelsLast.push(pixel); + } + else { + pixelsFirst.push(pixel); + } + } + adjacentCoords = [ + [0,1], + [0,-1], + [1,0], + [-1,0] + ]; + biCoords = [ + [0,1], + [1,0] + ]; + // Draw the current pixels + var canvas = document.getElementById("game"); + var ctx = canvas.getContext("2d"); + var pixelDrawList = pixelsFirst.concat(pixelsLast); + for (var i = 0; i < pixelDrawList.length; i++) { + pixel = pixelDrawList[i]; + if (pixelMap[pixel.x][pixel.y] == undefined) {continue} + if (view===null || view===3) { + ctx.fillStyle = pixel.color; + } + else if (view === 2) { // thermal view + // set the color to pixel.temp, from hottest at 0 hue to coldest 225 hue, with the minimum being -273, max being 6000 + var temp = pixel.temp; + if (temp < -273) {temp = -273} + if (temp > 6000) {temp = 6000} + var hue = 225 - (temp/6000)*225; + if (hue < 0) {hue = 0} + if (hue > 225) {hue = 225} + ctx.fillStyle = "hsl("+hue+",100%,50%)"; + } + else if (view === 4) { // smooth view, average of surrounding pixels + var colorlist = []; + // check adjacent coords on the pixelMap, add the color to the list if the pixel is not empty and the color indexOf "rgb" is not -1 + for (var j = 0; j < biCoords.length; j++) { + var x = pixel.x + biCoords[j][0]; + var y = pixel.y + biCoords[j][1]; + if (isEmpty(x,y,true) || elements[pixelMap[x][y].element].state !== elements[pixel.element].state) {continue} + var color = pixelMap[x][y].color; + if (color.indexOf("rgb") !== -1) { + colorlist.push(color.match(/\d+/g)); + } + } + if (colorlist.length === 0) { + ctx.fillStyle = pixel.color; + } + else { + ctx.fillStyle = averageRGB(colorlist); + } + } + if ((view === null || view === 4) && elements[pixel.element].state === "gas") { + ctx.globalAlpha = 0.66; + ctx.beginPath(); + ctx.moveTo((pixel.x-0.75)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1.5)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+0.5)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y-1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+1.75)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1.5)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.fill(); + ctx.globalAlpha = 1; + } + else { // draw the pixel (default) + ctx.beginPath(); + ctx.moveTo(pixel.x*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+0.5)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+1)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.fill(); + } + if (pixel.charge && view !== 2) { // Yellow glow on charge + if (!elements[pixel.element].colorOn) { + if ((view === null || view === 4) && elements[pixel.element].state === "gas") { + ctx.fillStyle = "rgba(255,255,0,0.5)"; + ctx.beginPath(); + ctx.moveTo((pixel.x-0.75)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1.5)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+0.5)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y-1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+1.75)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1.5)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.fill(); + } else { + ctx.fillStyle = "rgba(255,255,0,0.5)"; + ctx.beginPath(); + ctx.moveTo(pixel.x*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+0.5)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.lineTo((pixel.x+1)*pixelSize+(18*Math.sin((pixel.y+incrementt)/4.4)),(pixel.y+1)*pixelSize+(18*Math.sin((pixel.x+incrementt)/4.4))); + ctx.fill(); + } + } + } + } + if ((!paused) || forceTick) {pixelTicks++}; + } diff --git a/mods/triangles.js b/mods/triangles.js new file mode 100644 index 00000000..a9d04a84 --- /dev/null +++ b/mods/triangles.js @@ -0,0 +1,118 @@ + function drawPixels(forceTick=false) { + // newCurrentPixels = shuffled currentPixels + var newCurrentPixels = currentPixels.slice(); + var pixelsFirst = []; + var pixelsLast = []; + if (!paused || forceTick) { + shuffleArray(newCurrentPixels); + } + /*{newCurrentPixels.sort(function(p) { // shuffle the pixels but keep elements[p.element].isGas last + return 0.5 - Math.random(); + })} // shuffle the pixels if not paused*/ + for (var i = 0; i < newCurrentPixels.length; i++) { + pixel = newCurrentPixels[i]; + //if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue} + if (pixel.del) {continue} + if (!paused || forceTick) { + if (elements[pixel.element].tick) { // Run tick function if it exists + elements[pixel.element].tick(pixel); + } + if (pixel.del) {continue} + if (elements[pixel.element].behavior) { // Parse behavior if it exists + pixelTick(pixel); + } + }; + if (elements[pixel.element].isGas) { + pixelsLast.push(pixel); + } + else { + pixelsFirst.push(pixel); + } + } + adjacentCoords = [ + [0,1], + [0,-1], + [1,0], + [-1,0] + ]; + biCoords = [ + [0,1], + [1,0] + ]; + // Draw the current pixels + var canvas = document.getElementById("game"); + var ctx = canvas.getContext("2d"); + var pixelDrawList = pixelsFirst.concat(pixelsLast); + for (var i = 0; i < pixelDrawList.length; i++) { + pixel = pixelDrawList[i]; + if (pixelMap[pixel.x][pixel.y] == undefined) {continue} + if (view===null || view===3) { + ctx.fillStyle = pixel.color; + } + else if (view === 2) { // thermal view + // set the color to pixel.temp, from hottest at 0 hue to coldest 225 hue, with the minimum being -273, max being 6000 + var temp = pixel.temp; + if (temp < -273) {temp = -273} + if (temp > 6000) {temp = 6000} + var hue = 225 - (temp/6000)*225; + if (hue < 0) {hue = 0} + if (hue > 225) {hue = 225} + ctx.fillStyle = "hsl("+hue+",100%,50%)"; + } + else if (view === 4) { // smooth view, average of surrounding pixels + var colorlist = []; + // check adjacent coords on the pixelMap, add the color to the list if the pixel is not empty and the color indexOf "rgb" is not -1 + for (var j = 0; j < biCoords.length; j++) { + var x = pixel.x + biCoords[j][0]; + var y = pixel.y + biCoords[j][1]; + if (isEmpty(x,y,true) || elements[pixelMap[x][y].element].state !== elements[pixel.element].state) {continue} + var color = pixelMap[x][y].color; + if (color.indexOf("rgb") !== -1) { + colorlist.push(color.match(/\d+/g)); + } + } + if (colorlist.length === 0) { + ctx.fillStyle = pixel.color; + } + else { + ctx.fillStyle = averageRGB(colorlist); + } + } + if ((view === null || view === 4) && elements[pixel.element].state === "gas") { + ctx.globalAlpha = 0.66; + ctx.beginPath(); + ctx.moveTo((pixel.x-0.75)*pixelSize,(pixel.y+1.5)*pixelSize); + ctx.lineTo((pixel.x+0.5)*pixelSize,(pixel.y-1)*pixelSize); + ctx.lineTo((pixel.x+1.75)*pixelSize,(pixel.y+1.5)*pixelSize); + ctx.fill(); + ctx.globalAlpha = 1; + } + else { // draw the pixel (default) + ctx.beginPath(); + ctx.moveTo(pixel.x*pixelSize,(pixel.y+1)*pixelSize); + ctx.lineTo((pixel.x+0.5)*pixelSize,(pixel.y)*pixelSize); + ctx.lineTo((pixel.x+1)*pixelSize,(pixel.y+1)*pixelSize); + ctx.fill(); + } + if (pixel.charge && view !== 2) { // Yellow glow on charge + if (!elements[pixel.element].colorOn) { + if ((view === null || view === 4) && elements[pixel.element].state === "gas") { + ctx.fillStyle = "rgba(255,255,0,0.5)"; + ctx.beginPath(); + ctx.moveTo((pixel.x-0.75)*pixelSize,(pixel.y+1.5)*pixelSize); + ctx.lineTo((pixel.x+0.5)*pixelSize,(pixel.y-1)*pixelSize); + ctx.lineTo((pixel.x+1.75)*pixelSize,(pixel.y+1.5)*pixelSize); + ctx.fill(); + } else { + ctx.fillStyle = "rgba(255,255,0,0.5)"; + ctx.beginPath(); + ctx.moveTo(pixel.x*pixelSize,(pixel.y+1)*pixelSize); + ctx.lineTo((pixel.x+0.5)*pixelSize,(pixel.y)*pixelSize); + ctx.lineTo((pixel.x+1)*pixelSize,(pixel.y+1)*pixelSize); + ctx.fill(); + } + } + } + } + if ((!paused) || forceTick) {pixelTicks++}; + }