Star Grid

Simple grid of 5, 6, and 7 point stars.

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();
turtle.penup();
turtle.goto(0,0);
turtle.pendown();

const rows = 12;
const cols = 11;
const width = 200;
const height = 200;
const margin = 10;

function star(points, scale) {
    if (typeof(scale) === 'undefined') scale = 1.0;
    turtle.pendown();
    for (var i = 0; i < points; i++) {
        turtle.forward(10 * scale);
        turtle.right(720 / points);
        turtle.forward(10 * scale);
        turtle.left(720 / points / 2);
    }
    turtle.penup();
}

// The walk function will be called until it returns false.
function walk(i) {
    if (i >= rows * cols) return(false);
    var points = i % 3 + 5
    var row = Math.floor(i / cols);
    var col = i % cols;
    var x = -(width / 2) + margin  + ((width - 2 * margin) / cols) * col + (10);
    var y = -(height / 2) + margin  + ((height - 2 * margin) / rows) * row + (10 - points);
    turtle.penup();
    turtle.goto(x, y);
    star(points, 2 / points);
    return(true);
}