xxxxxxxxxx
43
// Set up canvas
function setup() {
createCanvas(800, 600);
background(0);
}
// Draw function
function draw() {
// Background gradient
for (let y = 0; y < height; y++) {
let gradient = map(y, 0, height, 0, 1);
let col = lerpColor(color(0, 0, 40), color(0, 0, 80), gradient);
stroke(col);
line(0, y, width, y);
}
// Random shapes
noStroke();
for (let i = 0; i < 200; i++) {
let x = random(width);
let y = random(height);
let size = random(10, 50);
let shapeColor = color(random(255), random(255), random(255), 100);
fill(shapeColor);
drawShape(x, y, size);
}
}
// Function to draw a random shape
function drawShape(x, y, size) {
let shapeType = floor(random(3));
if (shapeType === 0) {
ellipse(x, y, size, size);
} else if (shapeType === 1) {
rect(x, y, size, size);
} else {
triangle(x, y, x + size, y, x + size / 2, y - size);
}
}