Happy accidents.
Log in to post a comment.
Canvas.setpenopacity(1); const iters = 650000; const size = 61; const space = 1; const segments = 360*8; const turtle = new Turtle(); const startSide = Math.random() > 0.5; let ax, ay, j; let turned = 0; let tmp; let direction = "left"; let otherDirection = "right"; turtle.penup(); turtle.goto(randomStart(16, 31), randomStart(31, 16)); turtle.seth(randomStart(randomStart(45, 135), randomStart(215, 60))); 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 (ay > size && ax > size && turned < i-1) { turtle.seth(540+turtle.h()); changeDirection(); turned = i; } else if (ax > size && turned < i-1) { turtle.seth(540-turtle.h()); changeDirection(); turned = i; } else if (ay > size && turned < i-1) { turtle.seth(720-turtle.h()); changeDirection(); turned = i; } turtle[direction].call(turtle, 360/segments); turtle.forward(space*Math.floor(i/segments)*2*Math.PI/segments); if (i%segments === 0) { turtle.penup(); turtle[otherDirection].call(turtle, 90); turtle.forward(Math.floor(i/segments)/10*space/4); turtle[direction].call(turtle, 90); turtle.pendown(); } return i < iters; }