xxxxxxxxxx
47
let bgcolor = (100, 100, 100);
function setup() {
createCanvas(600, 600);
}
function draw() {
background(bgcolor);
ground();
flower();
// Map values for interaction
let servoAngle = int(map(mouseY, 0, height, 0, 180));
let ledBrightness = int(map(mouseY, 0, height, 0, 255));
let ledColor = int(map(mouseX, 0, width, 0, 255));
// Display debug information on the canvas
fill(255);
textSize(16);
text(`Servo Angle: ${servoAngle}`, 20, 20);
text(`LED Brightness: ${ledBrightness}`, 20, 40);
text(`LED Color: ${ledColor}`, 20, 60);
}
function ground() {
fill(170, 150, 146, 240);
rect(0, height * 0.85, width, height * 0.15);
}
function flower() {
stroke(85, 107, 47, 20);
strokeWeight(3);
line(width / 2, height * 0.85, width / 2, height / 2);
noStroke();
// Petals
push();
fill(230, 190, 230, 240);
translate(width / 2, height / 2);
for (let i = 0; i < 10; i++) {
let petalSize = map(mouseY, 0, height, 25, 50);
ellipse(0, 40, petalSize, petalSize * 2);
rotate(PI / 5);
}
pop();
}