A spiral of a 'regular polygon' where the number of edges is increased with every full rotation.

Log in to post a comment.

// 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(); const pi2 = Math.PI * 2; const precision = .001; const polygons = 25; const add2 = (a, b) => [a[0]+b[0], a[1]+b[1]]; const scale2 = (a, s) => [a[0]*s, a[1]*s]; const modClip = (val, lowerBound, upperBound) => { const diff = upperBound - lowerBound; while(val < lowerBound) val += diff; while(val > upperBound) val -= diff; return val; } const regularPolygonPoint = (theta, polygonEdgeCount) => scale2([Math.cos(theta * pi2), Math.sin(theta * pi2)], Math.cos(Math.PI / polygonEdgeCount) / Math.cos(modClip(theta * pi2, 0, pi2 / polygonEdgeCount) - (Math.PI / polygonEdgeCount))) // The walk function will be called until it returns false. function walk(i) { turtle.goto(scale2(regularPolygonPoint(i*precision, 2 + (i*precision | 0)), polygons * 6 * (i / (polygons/precision)))); return i < polygons/precision; }