xxxxxxxxxx
let colors = [];
let titleFont;
let gridSize = 80; // Smaller grid size for more variety
var refreshButton;
function preload() {
// Load font
titleFont = loadFont('Mont-HeavyDEMO.otf');
}
function setup() {
createCanvas(500, 700);
background(220);
// Define a palette of colors
colors = [
color(245, 245, 220), // Beige
color(80, 90, 130), // Blue
color(40, 20, 50), // Black
color(230, 90, 80), // Red
color(200, 150, 100), // Brown
color(255, 255, 240) // White
];
// Initialize refresh button
refreshButton = createButton('Refresh Design');
refreshButton.position(10, height + 10);
refreshButton.mousePressed(refreshBtnPressed);
// Disable continuous loop
noLoop();
}
function refreshBtnPressed() {
// Redraw the canvas when button is pressed
draw();
}
function draw() {
background(colors[0]); // Set background to beige
// Title Text
textAlign(CENTER);
fill(colors[2]); // Black
textFont(titleFont);
textSize(22);
text('Explorations in Design', width / 2, 40);
// Subtitle
textSize(18);
text('A Journey Through Generative Art', width / 2, 70);
// Decorative Line
stroke(colors[2]);
line(50, 90, width - 50, 90);
// Grid Area
push();
translate(50, 120); // Move grid area
for (let i = 0; i < 5; i++) { // 5 columns
for (let j = 0; j < 6; j++) { // 6 rows
let x = i * gridSize;
let y = j * gridSize;
push();
translate(x, y);
// Randomly decide whether to draw a triangle or circle
let choice = random(1);
if (choice < 0.5) {
// Draw triangle
fill(random(colors)); // Random color from palette
noStroke();
triangle(0, 0, gridSize, gridSize, 0, gridSize);
} else {
// Draw circle
noFill();
stroke(random(colors)); // Random stroke color
strokeWeight(2);
ellipse(gridSize / 2, gridSize / 2, gridSize * 0.8);
}
pop();
}
}
pop();
// Footer Text
textSize(14);
fill(colors[2]); // Black
textAlign(CENTER);
text('Press "s" to Save this Artwork', width / 2, height - 20);
}
function keyPressed() {
if (key === 's') {
saveCanvas('generative_art_poster', 'jpg');
}
}