An attempt at wavefront simulation.
Log in to post a comment.
Canvas.setpenopacity(-0.05); const iters = 15000000; const size = 60; const space = 2; const segments = 360*30; const turtle = new Turtle(); const startSide = Math.random() > 0.5; let ax, ay, j; let tmp; let direction = "left"; let otherDirection = "right"; let inside = true; turtle.penup(); turtle.goto(16, -31); turtle.seth(45); turtle.pendown(); function randomStart(n, m) { return Math.random() > 0.5 ? (Math.random() > 0.5 ? n : -n) : (Math.random() > 0.5 ? m : -m); } function changeDirection() { tmp = otherDirection; otherDirection = direction; direction = tmp; } function walk(i) { ax = Math.abs(turtle.x()); ay = Math.abs(turtle.y()); if (inside && ay >= size && ax >= size) { turtle.seth(540+turtle.h()); changeDirection(); inside = false; } else if (inside && ax >= size) { turtle.seth(540-turtle.h()); changeDirection(); inside = false; } else if (inside && ay >= size) { turtle.seth(720-turtle.h()); changeDirection(); inside = false; } else if (Math.floor(ay) <= size && Math.floor(ax) <= size) { inside = true; } turtle[direction](360/segments); turtle.forward(space*Math.floor(i/segments)*2*Math.PI/segments/20); if (i%segments === 0) { turtle.penup(); turtle[otherDirection](90); turtle.forward(space/20); turtle[direction](90); turtle.pendown(); } return i < iters; }