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.
// Forked from "ExagonRandom" by nina // https://turtletoy.net/turtle/bc0fa5f383 // Hexagon Truchet. Created by EZ // const turtle = new Turtle(); const count = 200; // min=100 max=20000 step=20 const minsize = 5; // min=1 max=50 step=1 //funzione per disegnare un esagono con lunghezza casuale function drawHexagon() { for (let i = 0; i < 6; i++) { turtle.forward(Math.random() * 10 + minsize); turtle.right(60); } } //funzione per creare il pattern Truchet con angoli casuali function drawTruchet() { for (let i = 0; i < count; i++) { drawHexagon(); turtle.right(Math.random() * 90); drawHexagon(); turtle.right(Math.random() * 90); } } //chiamo la funzione per creare il pattern drawTruchet();