xxxxxxxxxx
// number of repetitions
let num = 30;
let r, g, b;
let rotationAngle = 0;
function setup() {
createCanvas(500, 700);
noLoop();
angleMode(DEGREES);
// Random initial colors
r = random(255);
g = random(255);
b = random(255);
}
function draw() {
background(0);
translate(width / 2, height / 2);
for (let i = 0; i < num; i++) {
let scaleFactor = map(i, 0, num, 0.2, 1);
push();
stroke(r, g, b, random(0, 255));
rotate(rotationAngle);
scale(scaleFactor);
customShape();
pop();
rotationAngle += 360 / num; // evenly distribute elements in a circle
}
// Text
push();
fill(255);
textFont('Arial');
textSize(42);
textAlign(CENTER, CENTER);
text('DIVERSE', 0, -height / 3); // Adjust position
pop();
// Date
push();
fill(r, g, b);
textAlign(CENTER);
textSize(22);
text('12 / 06', 0, height / 3); // Adjust position
pop();
}
function customShape() {
noFill();
strokeWeight(random(1, 10));
// Draw a circular shape
beginShape();
for (let i = 0; i < 360; i += 30) {
let radius = height / 5 + random(-20, 20);
let x = cos(i) * radius;
let y = sin(i) * radius;
vertex(x, y);
}
endShape(CLOSE);
}
function keyPressed() {
if (key === 't') {
num = int(random(3, 40));
r = random(0, 255);
g = random(0, 255);
b = random(0, 255);
rotationAngle = 0; // reset rotation angle
redraw(); // Use redraw to force the draw function to execute
}
if (key === 's') {
saveCanvas('generative_poster', 'jpg'); // Save as JPEG
}
}