xxxxxxxxxx
74
let buldPos;
let bulbR = 255;
let bulbG = 255;
let bulbB = 255;
let bulbAlpha = 255;
function setup() {
createCanvas(500, 500);
}
function draw() {
background(200);
bulbPos = 50;
// Loop to draw five circles
for (let i = 0; i < 5; i++) {
let bulbPos = 50 + i * 100; // Calculate position for each circle
fill(bulbR, bulbG, bulbB, bulbAlpha);
ellipse(bulbPos, height / 2, 50, 50); // Draw the circle
}
// Create buttons
let button1 = createButton("All");
button1.position(40, 350);
button1.mousePressed(all);
let button2 = createButton("Random");
button2.position(80, 350);
button2.mousePressed(randomLight);
let button3 = createButton("One");
button3.position(160, 350);
button3.mousePressed(oneLight);
let button4 = createButton("Reset");
button4.position(220, 350);
button4.mousePressed(resetLight);
let button5 = createButton("Dim");
button5.position(280, 350);
button5.mousePressed(dimLight);
}
function all() {
bulbB = 0;
}
function randomLight() {
bulbR = random(255);
bulbG = random(255);
bulbB = random(255);
}
function oneLight(){
resetLight()
let index = floor(random(bulbPos));
bulbPos.r = 255;
bulbPos.g = 255;
bulbPos.b = 0;
}
function resetLight(){
bulbR = 255;
bulbG = 255;
bulbB = 255;
bulbAlpha = 255;
}
function dimLight() {
bulbB = 0;
bulbAlpha = 50;
}