Adapted from contextfreeart.org/gallery2/index.html#design/1123
Log in to post a comment.
// You can find the Turtle API reference here: https://turtletoy.net/syntax Canvas.setpenopacity(-1); const turtle = new Turtle(); turtle.penup(); function divide(x, y, w, h) { if (w < 2) return false; box(x - w * 0.25, y - w * 0.25, w * 0.5); box(x + w * 0.25, y - w * 0.25, w * 0.5); box(x - w * 0.25, y + w * 0.25, w * 0.5); box(x + w * 0.25, y + w * 0.25, w * 0.5); return true; } // box rules function box(x, y, w) { const r = Math.random() * 3.6; switch (true) { case r < 0.1: break; case r < 0.5: divide(x, y, w * 0.5); break; case r < 2.4: divide(x, y, w); break; default: square(x, y, w * 0.8); } } // draw square function square(x, y, w) { for (let i = w; i > w * 0.8; i -= 0.2) { const r = i * 0.5; turtle.goto(x - r, y - r); turtle.down(); turtle.goto(x + r, y - r); turtle.goto(x + r, y + r); turtle.goto(x - r, y + r); turtle.goto(x - r, y - r); } turtle.up(); } // go divide(0, 0, 180, 180);