10Print

Not just one line of code but it works.
See: https://10print.org/

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
// Released under the MIT licence 
// https://mit-license.org/
// you can use this for commercial gain if you like eg you can sell artworks with this image.

Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();
const gap = 12; //min=1 max=12 step=1
const gridCount = 15; //min=1 max=20 step=1
const size = 11; //min=5 max=12 step=1
const xOffset = -90; //min=-100 max=80 step=1
const yOffset = -90; //min=-100 max=80 step=1
const outline = 0;//min=0 max=1 step=1 (No, Yes)

for(let x=0; x < gridCount; x++){
    for(let y=0; y < gridCount; y++){
    square((x * gap) + xOffset, (y * gap)+ yOffset);
    }
}


function square(x,y) {
    
    // Pick a random number
    let r = randomInRange(0, 2);
    
    turtle.penup();
    turtle.goto(x,y);
    turtle.pendown();
    
    
    if(outline === 1){
        for(let i=0; i< 4; i++){
            turtle.forward(size);
            turtle.right(90);
        }
    }
    
    
    switch(r) {
    case 0:
        turtle.right(45);
        turtle.forward(size * Math.sqrt(2));
        turtle.backward(size * Math.sqrt(2));
        turtle.left(45);
    break;
    case 1:
        turtle.penup();
        turtle.forward(size);
        turtle.pendown();
        turtle.right(90 + 45);
        turtle.forward(size * Math.sqrt(2));
        turtle.backward(size * Math.sqrt(2));
        turtle.left(90 + 45);
        turtle.penup();
        turtle.backward(size);
    break;
    default:
    // code block
    }
}

function randomInRange(from, to) {
  var r = Math.random();
  return Math.floor(r * (to - from) + from);
}