xxxxxxxxxx
37
// Parametric Music Note Drawing in p5.js with variable shape, size, and color
let noteColors = ["#FF4500", "#4682B4", "#32CD32", "#FFD700", "#8A2BE2"];
function setup() {
createCanvas(400, 400);
noLoop();
}
function draw() {
background(240);
let noteColor = random(noteColors);
// Randomized note dimensions
let noteX = width / 2;
let noteY = height / 2;
let noteSize = random(40, 60);
let stemHeight = random(80, 100);
// Draw note head
fill(noteColor);
noStroke();
ellipse(noteX, noteY, noteSize, noteSize * 0.8);
// Draw note stem
rectMode(CENTER);
rect(noteX + noteSize / 3, noteY - stemHeight / 2, 8, stemHeight);
// Draw flag (optional, for eighth note)
if (random() > 0.5) {
beginShape();
vertex(noteX + noteSize / 3 + 4, noteY - stemHeight);
vertex(noteX + noteSize / 3 + 20, noteY - stemHeight + 15);
vertex(noteX + noteSize / 3 + 15, noteY - stemHeight + 25);
vertex(noteX + noteSize / 3, noteY - stemHeight + 10);
endShape(CLOSE);
}
}