Log in to post a comment.
const zoom = .7; //min=.2 max=10 step=.1 // You can find the Turtle API reference here: https://turtletoy.net/syntax Canvas.setpenopacity(-1); // Global code will be evaluated once. const turtle = new Turtle(); function* step(s, steps = 0) { while(++steps) { for(let i = 0; i < 2; i++) { for(let j = 0; j < steps; j++) yield turtle.forward(s); turtle.left(90); } } } const isPrime = num => { for(let i = 2, s = Math.sqrt(num); i <= s; i++) if(num % i === 0) return false; return num > 1; } const point = (radius) => { radius = Math.max(.2, radius); [px, py] = turtle.pos(); turtle.jump(px+radius,py); for(let i = 0, max = Math.ceil(radius*2*Math.PI); i <= max; i++) { turtle.goto(px+Math.cos(2*Math.PI*i/max)*radius, py-Math.sin(2*Math.PI*i/max)*radius); } turtle.jump(px, py); } const stepIterator = step(zoom); // The walk function will be called until it returns false. function walk(i) { if(isPrime(i + 1)) {point(zoom/3);point(zoom/2);} turtle.up(); stepIterator.next(); turtle.down(); return turtle.x() <= 101; }