From 93f8e452bc8a2e24c8205327c4b1a4cc57f8c340 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:01:27 -0500 Subject: [PATCH] f --- mod-list.html | 1 + mods/fractals.js | 156 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 mods/fractals.js diff --git a/mod-list.html b/mod-list.html index 65ecc76e..a2b74b4d 100644 --- a/mod-list.html +++ b/mod-list.html @@ -342,6 +342,7 @@ Visual Effects acid_and_shapes.jsWeird visual effects. Enable in SettingsAlice customBackground.jsSet your background to an image linkJayd +fractals.jsAdds an element and tools to render fractals in gamenousernamefound heatglow.jsRed glowing effect for hot metalsnousernamefound invisible_dye.jsAdds elements like Dye and Spray Paint that take the color of the backgroundAlice invisible_wall.jsAdds an element like Wall that takes the color of the backgroundAlice diff --git a/mods/fractals.js b/mods/fractals.js new file mode 100644 index 00000000..b2b7279f --- /dev/null +++ b/mods/fractals.js @@ -0,0 +1,156 @@ +let jmax = 2 +let jmin = -2 +let offsetx = 0 +let offsety = 0 +let mode = `mandelbrot` +preCalculatedGrid = [] +runEveryTick(function(){ + preCalculatedGrid = [] + for (let x = 0; x < pixelMap.length; x++){ + preCalculatedGrid.push([]) + for (let y = 0; y < pixelMap[x].length; y++){ + preCalculatedGrid[x].push({ + x: x, + y: y, + iteration: 100, + }) + } + } + for (let ix = 0; ix < preCalculatedGrid.length; ix++){ + for (let iy = 0; iy < preCalculatedGrid[ix].length; iy++){ + const range = jmax - jmin; + const scale = range / Math.min(width, height); + let x = (ix - width / 2) * scale + offsetx; + let y = (iy - height / 2) * scale + offsety; + let iteration = 0; + if (mode == `mandelbrot`){ + let zx = 0; + let zy = 0; + let c = {x: x, y: y}; + while (zx * zx + zy * zy < 4 && iteration < 100) { + let xtemp = zx * zx - zy * zy + c.x; + zy = 2 * zx * zy + c.y; + zx = xtemp; + iteration++; + }} + else { // burning ship + let zx = 0; + let zy = 0; + let c = {x: x, y: y}; + while (zx * zx + zy * zy < 4 && iteration < 100) { + let xtemp = zx * zx - zy * zy + c.x; + zy = Math.abs(2 * zx * zy) + c.y; + zx = Math.abs(xtemp); + iteration++; + } + } + preCalculatedGrid[ix][iy].iteration = iteration + } + } +}) +elements.mandelbrot = { + color: "#000000", + behavior: behaviors.WALL, + category: "mandelbrot tools", + onSelect: function(){ + jmax = parseFloat(prompt("How far would you like it to extend in each direction?"))||2 + jmin = -jmax + offsetx = parseFloat(prompt("How far would you like it to be offset in the x direction?"))||0 + offsety = parseFloat(prompt("How far would you like it to be offset in the y direction?"))||0 + mode = prompt("Mandelbrot or burning ship?") + }, + tick: function(pixel){ + // first, map canvas coord to a range of -2 to 2, but dont scale it, using width, height, and pixel.x and pixel.y + /* + const range = jmax - jmin; + const scale = range / Math.min(width, height); + const x = (pixel.x - width / 2) * scale + offsetx; + const y = -(pixel.y - height / 2) * scale + offsety; + let iteration = 0; + if (mode == `mandelbrot`){ + let zx = 0; + let zy = 0; + let c = {x: x, y: y}; + while (zx * zx + zy * zy < 4 && iteration < 100) { + let xtemp = zx * zx - zy * zy + c.x; + zy = 2 * zx * zy + c.y; + zx = xtemp; + iteration++; + }} + else { // burning ship + let zx = 0; + let zy = 0; + let c = {x: x, y: y}; + while (zx * zx + zy * zy < 4 && iteration < 100) { + let xtemp = zx * zx - zy * zy + c.x; + zy = Math.abs(2 * zx * zy) + c.y; + zx = Math.abs(xtemp); + iteration++; + } + } + */ + iteration = gridWeightedAverage(pixel.x, pixel.y) + if (iteration >= 99.5) { + pixel.color = "rgb(255, 255, 255)" + } else { + pixel.color = `rgb(0, ${67.3684*Math.pow(1.01578, iteration)-67.3684}, ${67.3684*Math.pow(1.01578, iteration)-67.3684})` + //console.log(iteration) + } + } +} +elements.mandelbrot_zoom_in = { + color: elements.heater.color, + category: "mandelbrot tools", + canPlace: false, + tool: function(){}, + onSelect: function(){ + jmax *= 0.95 + jmin = -jmax + } +} +elements.mandelbrot_zoom_out = { + color: elements.cooler.color, + category: "mandelbrot tools", + canPlace: false, + tool: function(){}, + onSelect: function(){ + jmax *= 1.05 + jmin = -jmax + } +} +elements.mandelbrot_move_left = { + color: elements.grape.color, + category: "mandelbrot tools", + canPlace: false, + tool: function(){}, + onSelect: function(){ + offsetx -= 0.05*jmax + } +} +elements.mandelbrot_move_right = { + color: elements.tomato.color, + category: "mandelbrot tools", + canPlace: false, + tool: function(){}, + onSelect: function(){ + offsetx += 0.05*jmax + } +} +elements.mandelbrot_move_up = { + color: elements.mix.color, + category: "mandelbrot tools", + canPlace: false, + tool: function(){}, + onSelect: function(){ + offsety += 0.05*jmax + } +} +elements.mandelbrot_move_down = { + color: elements.drag.color, + category: "mandelbrot tools", + canPlace: false, + tool: function(){}, + onSelect: function(){ + offsety -= 0.05*jmax + } +} \ No newline at end of file