xxxxxxxxxx
// Lamp Base Variables
let baseW, baseH, xb, yb;
// Stand Variables
let standW, standH, xs, ys;
// Lampshade Variables
let shadeW, shadeH, xShade, yShade;
// Light Effect
let lightIntensity;
let lightOn = true; // Starts with light on
// Color Arrays
let baseColors = ["#A2D2FF", "#BDE0FE", "#FFAFCC", "#FFC8A2", "#D0F4DE"]; // Base colors
let shadeColors = ["#FAF3DD", "#FFD6A5", "#FFB703", "#FB8500"]; // Lampshade colors
function setup() {
createCanvas(600, 600);
background(255);
noLoop();
// Randomize lamp base size and position
baseW = random(80, 120);
baseH = random(20, 30);
xb = width / 2 - baseW / 2;
yb = height - 100;
// Randomize stand size and position
standW = random(8, 12);
standH = random(100, 150);
xs = width / 2 - standW / 2;
ys = yb - standH;
// Randomize lampshade size and position
shadeW = baseW * random(1.2, 1.6);
shadeH = random(50, 80);
xShade = width / 2 - shadeW / 2;
yShade = ys - shadeH;
// Randomize light intensity
lightIntensity = random(100, 200);
}
function draw() {
noStroke();
// Glow effect when light is ON
if (lightOn) {
fill(255, 255, 150, lightIntensity); // Yellow glow effect
ellipse(width / 2, yShade + shadeH / 2, shadeW * 1.5, shadeH * 1.2);
}
// Draw Stand
fill(100);
rect(xs, ys, standW, standH);
// Draw Base
fill(random(baseColors)); // Random color for base
rect(xb, yb, baseW, baseH, 10);
// Draw Lampshade
fill(random(shadeColors)); // Random color for lampshade
arc(width / 2, yShade + shadeH, shadeW, shadeH, PI, TWO_PI);
}
// Toggle Light ON/OFF when pressing 'L'
function keyPressed() {
if (key === 'L' || key === 'l') {
lightOn = !lightOn;
} else if (key === 'R' || key === 'r') {
setup(); // Reset lamp properties randomly
}
redraw();
}