...loading...
Canvas size:
Grid:
Rub the Lamp! - Stage
...loading...
Canvas size:
Grid:
Magic Lamp uses two powerhouse SW classes — SWSinusoid and SWColor — to conjure a warm, pulsing glow that awakens whenever you hover over the lamp. No genie required!
✨ How to Use This App
🟡 SWSinusoid — The Pulse Engine
The glow doesn’t just appear — it breathes. That living quality comes entirely from SWSinusoid, which models a sine wave with configurable amplitude, frequency, vertical shift, and phase. In setup(), one sinusoid is created:
glowSinusoid = new SWSinusoid(0.5, 1.5, 0.8, 0);
Every frame, glowSinusoid.getValue(currentTime) returns a smoothly oscillating value that drives the size and opacity of every glow layer simultaneously. The result is an organic, candle-like flicker — all from a single method call. Without SWSinusoid, replicating this would require hand-rolling the sine math, managing time yourself, and threading the result through every draw call.
🟠 SWColor — The Color Wizard
Every shade of warmth you see — the deep purple background, the burnished gold, the soft inner core, the bright white center point — is an SWColor object working in HSB color space. The glow layers are built by copying a swGold preset color and then mutating its hue, saturation, brightness, and alpha per layer:
let glowColor = SWColor.copy(swGold);
glowColor.setAlphaTo(layerAlpha);
glowColor.h = (glowColor.h - (i * 3)) % 360;
This HSB approach makes color relationships intuitive: shifting the hue a few degrees warms or cools the glow, adjusting brightness brightens or dims it, and tweaking alpha controls how translucent each layer is. Stacking eight of these semi-transparent rings produces a smooth radial gradient effect — pure SWColor magic.
SWColor also powers the animated background gradient. lerpSWColor(swPurple, swGold, t) blends two SW color presets by interpolating their H, S, B, and A channels independently, then draws one horizontal line per pixel row — giving the canvas its rich purple-to-gold sweep every frame.
🪔 Key Features Demonstrated
getValue(t) call animates the entire glow system.isMouseOverLamp() compares mouseX / mouseY against the pre-computed lampBounds rectangle to decide whether the glow is active.lerpSWColor() blends two SWColor presets row-by-row every frame, creating the purple-to-gold canvas backdrop.🤖 How Copilot Built This
The concept was simple: a lamp that glows when you hover over it. The interesting design question was “how do you make the glow feel alive?” A static colored circle would look flat. A glow that just switches on and off would look cheap. What I wanted was something warm, organic, and flickering — like a real flame.
SWSinusoid was the obvious answer. One instance, sampled with millis() / 1000 as the time argument, gives a continuously varying float that I could pipe directly into glow size and alpha. I didn’t write a single line of sine math myself — I just asked the sinusoid what the intensity should be at this moment and used the answer everywhere at once.
For the actual glow rendering, the trick is layering. One circle looks like a dot. Eight semi-transparent circles of increasing radius, drawn from largest to smallest, blend together into a soft bloom. SWColor made this elegant: I copied swGold, then shifted the hue and alpha on each copy to warm the outer layers slightly and fade them out. HSB color space is perfect for this because “make it warmer” is literally “decrease the hue by a few degrees” — no RGB arithmetic required.
The gradient background is the same idea applied to the canvas itself. lerpSWColor(swPurple, swGold, t) blends the two presets at each row, turning a loop into a single expressive line. The result is a rich jewel-toned backdrop that makes the golden lamp pop — and it cost almost nothing to write because SWColor handles all the interpolation math internally.
The lesson here: when your tools model the right abstractions, the interesting problems become the only problems. SWSinusoid meant I never thought about sine math — only glow personality. SWColor meant I never thought about channel arithmetic — only warmth and mood. That’s the payoff of a well-designed class library!