xxxxxxxxxx
let totalShapes = 220;
let zoomFactor = 1;
function setup() {
createCanvas(800, 800);
drawShapes(totalShapes);
}
function drawShapes(numShapes) {
background(0); // Black background
noFill(); // No fill for rectangles and squares
translate(width / 2, height / 2); // Translate to the center of the canvas
scale(zoomFactor); // Apply the zoom factor
translate(-width / 2, -height / 2); // Translate back
for (let i = 0; i < numShapes; i++) {
let shapeType = int(random(3)); // Randomly choose between rectangle, square, or line
let x = random(width);
let y = random(height);
let w = random(20, 100);
let h = random(20, 100);
if (shapeType == 0) {
// Draw a rectangle with red outline
stroke(249, 190, 199); // Red color
rect(x, y, w, h);
} else if (shapeType == 1) {
// Draw a square with green outline
let size = random(20, 100);
stroke(237, 220, 210); // Green color
rect(x, y, size, size);
} else {
// Draw a line with blue color
let x2 = x + random(-50, 50);
let y2 = y + random(-50, 50);
stroke(188, 212, 230); // Blue color
line(x, y, x2, y2);
}
}
}
function keyPressed() {
if (keyCode === ENTER) {
zoomFactor *= 1.2; // Increase zoom factor by 20%
drawShapes(totalShapes); // Redraw shapes with the new zoom factor
} else if (key === 's' || key === 'S') {
saveCanvas('myCanvas', 'png'); // Save the canvas as a PNG file
}
}
function draw() {
noLoop(); // No need to draw continuously for this static design
}