xxxxxxxxxx
let shapes = [];
function setup() {
createCanvas(500, 700);
noStroke();
noLoop();
generateShapes();
}
function draw() {
background(245, 245, 220);
// Draw shapes
for (let shape of shapes) {
fill(shape.color);
drawShape(shape);
}
// Add text and lines
drawText("Generative Poster", width / 2, 30, CENTER, "Montserrat", 28);
drawLine(50);
drawText("Abstract Art", width / 2, height - 20, CENTER, "Montserrat", 18);
}
function generateShapes() {
// Generate random shapes
for (let i = 0; i < 10; i++) {
let shape = {
type: int(random(3)), // 0: ellipse, 1: rectangle, 2: triangle
x: random(width),
y: random(height / 3, (2 * height) / 3),
size: random(50, 150),
color: color(random(255), random(255), random(255), random(150, 200)),
};
shapes.push(shape);
}
}
function drawShape(shape) {
push();
translate(shape.x, shape.y);
if (shape.type === 0) {
ellipse(0, 0, shape.size, shape.size);
} else if (shape.type === 1) {
rectMode(CENTER);
rect(0, 0, shape.size, shape.size);
} else if (shape.type === 2) {
triangle(0, -shape.size / 2, -shape.size / 2, shape.size / 2, shape.size / 2, shape.size / 2);
}
pop();
}
function drawText(txt, x, y, align, font, size) {
textAlign(align);
fill(0);
textFont(font);
textSize(size);
text(txt, x, y);
}
function drawLine(y) {
stroke(0);
line(0, y, width, y);
}