xxxxxxxxxx
// Parametric Guitar Drawing in p5.js with variable shape, size, and color
let colors = ["#8B4513", "#A0522D", "#D2691E", "#CD853F", "#DEB887"];
function setup() {
createCanvas(400, 400);
noLoop();
}
function draw() {
background(240);
let bodyColor = random(colors);
let neckColor = random(colors);
let stringColor = "#000000";
// Randomized guitar body dimensions
let bodyWidth = random(80, 120);
let bodyHeight = random(140, 180);
let bodyX = width / 2;
let bodyY = height / 2 + 20;
// Randomized neck dimensions
let neckWidth = random(15, 25);
let neckHeight = random(100, 140);
// Draw guitar body
fill(bodyColor);
noStroke();
ellipse(bodyX, bodyY, bodyWidth, bodyHeight);
// Draw guitar neck
fill(neckColor);
rectMode(CENTER);
rect(bodyX, bodyY - bodyHeight / 2 - neckHeight / 2, neckWidth, neckHeight);
// Draw sound hole
fill(0);
ellipse(bodyX, bodyY, random(15, 25), random(15, 25));
// Draw guitar strings
stroke(stringColor);
strokeWeight(1.5);
for (let i = -2; i <= 2; i++) {
line(
bodyX + i * 3,
bodyY - bodyHeight / 2 - neckHeight / 2,
bodyX + i * 3,
bodyY + bodyHeight / 3
);
}
}