ExagonRandom

This code creates a pattern called "Truchet" using hexagons. The turtle object is used to draw the pattern. The "drawHexagon" function is defined to draw a hexagon with a random length by repeatedly moving forward and turning right by 60 degrees. The "drawTruchet" function is defined to create the Truchet pattern by calling the "drawHexagon" function multiple times and rotating the turtle by a random angle before each call. Finally, the "drawTruchet" function is called to create the pattern.

Log in to post a comment.

// Hexagon Truchet. Created by EZ
//

const turtle = new Turtle();

//funzione per disegnare un esagono con lunghezza casuale
function drawHexagon() {
  for (let i = 0; i < 6; i++) {
    turtle.forward(Math.random() * 50 + 50);
    turtle.right(60);
  }
}

//funzione per creare il pattern Truchet con angoli casuali
function drawTruchet() {
  for (let i = 0; i < 4; i++) {
    drawHexagon();
    turtle.right(Math.random() * 90);
    drawHexagon();
    turtle.right(Math.random() * 90);
  }
}

//chiamo la funzione per creare il pattern
drawTruchet();