xxxxxxxxxx
let container = [];
let num = 70;
let noteColors = ["#FF4500", "#4682B4", "#32CD32", "#FFD700", "#8A2BE2"];
function setup() {
createCanvas(windowWidth, windowHeight);
noLoop();
for (let i = 0; i < num; i++) {
let x = random(0, width);
let y = random(0, height);
let sizeFactor = random() > 0.7 ? random(60, 100) : random(30, 50); // Some notes are larger
container.push({ x, y, sizeFactor });
}
}
function draw() {
background(240);
for (let i = 0; i < num; i++) {
drawMusicNote(container[i].x, container[i].y, container[i].sizeFactor);
}
}
function drawMusicNote(x, y, noteSize) {
let noteColor = random(noteColors);
let stemHeight = noteSize * random(1.5, 2);
fill(noteColor);
noStroke();
ellipse(x, y, noteSize, noteSize * 0.8);
rectMode(CENTER);
rect(x + noteSize / 3, y - stemHeight / 2, 8, stemHeight);
if (random() > 0.5) {
beginShape();
vertex(x + noteSize / 3 + 4, y - stemHeight);
vertex(x + noteSize / 3 + 20, y - stemHeight + 15);
vertex(x + noteSize / 3 + 15, y - stemHeight + 25);
vertex(x + noteSize / 3, y - stemHeight + 10);
endShape(CLOSE);
}
}
function keyPressed() {
if (key === 's' || key === 'S') {
saveCanvas('music_notes', 'png');
}
}