xxxxxxxxxx
function setup() {
createCanvas(400, 600);
background(255);
noLoop(); // Prevent the draw function from continuously executing.
drawArtwork(); // Call the function to draw the artwork.
}
function draw() {
}
function drawArtwork() {
let numShapes = 700; // Number of shapes
for (let i = 0; i < numShapes; i++) {
let x = random(width); // Generate a random x-coordinate within the canvas.
let y = random(height); // Generate a random y-coordinate within the canvas.
let size = random(20, 30);
let rotation = random(TWO_PI);
drawShape(x, y, size, rotation); // Call the function to draw a shape with random parameters.
}
}
function drawShape(x, y, size, rotation) {
push(); // Save the current transformation state.
translate(x, y); // Translate the origin to the specified (x, y) position.
rotate(rotation);
stroke(random(225), random(255), random(240));
noFill(); // Disable filling shapes.
strokeWeight(random(1,2));
let sides = int(random(3, 4));
beginShape(); // Start defining the shape.
for (let j = 0; j < sides; j++) {
let angle = TWO_PI / sides * j;
let xOffset = cos(angle) * size; // Calculate the x-coordinate of the vertex.
let yOffset = sin(angle) * size; // Calculate the y-coordinate of the vertex.
vertex(xOffset, yOffset); // Add a vertex to the shape.
}
endShape(CLOSE); // Close the shape by connecting the last vertex to the first.
pop(); // Restore the previous transformation state.
}