Skip to content
Module: Science

Concepts

The Chameleon Lamp relies on seven key concepts. Some are shared with the Colour Picker; others are unique to the continuous-loop design.

1. Auto-Ranging (Like Human Pupils)

The Pupil Analogy

"Have you ever walked from a dark movie theater out into the bright sunshine? Your pupils shrink to let less light in so you are not blinded. The lamp does the exact same thing every few seconds!"

If the lamp is sitting on bright white paper, it lowers the sensor's sensitivity. If it is on a dark book, it increases sensitivity to see better. This adaptive behavior keeps readings accurate regardless of ambient light.

2. The Trimmed Mean (Ignoring Glitches)

Sensors are not perfect. Sometimes they record a random flash of light or a weird shadow. The lamp takes five pictures of the surface in a row, lines up the results, throws away the brightest and the darkest, and averages the remaining three.

Key Takeaway

This guarantees that one random glitch will not cause the lamp to flash the wrong color. It is the same scoring system used in Olympic gymnastics!

3. Black Level Correction (Cleaning Up the Mud)

The Dirty Window Analogy

"Imagine looking through a slightly dirty window. Everything has a dull, grey tint over it. Black Level Correction is like cleaning that window — it removes the grey baseline so you see pure, true colors."

Color sensor filters are not perfect — a little bit of light leaks across the red, green, and blue channels, creating a muddy grey baseline. The program finds the weakest channel and subtracts it from everything, stripping away the noise.

4. Saturation Boost (Making It Pop)

Sometimes, the color a sensor sees looks a little washed out compared to how our brains perceive it. The program includes a mathematical boost that pushes the dominant color stronger while pushing weaker colors down. This ensures the lamp creates deep, vivid colors rather than pale pastels.

Key Takeaway

This is the same thing Instagram filters and photo editing apps do when you drag the saturation slider to the right!

5. Gamma Correction (Translating for Human Eyes)

Robots and humans see light very differently. If a computer turns an LED on at 50 percent power, the computer thinks it is half bright. But to a human eye, it actually looks almost fully bright! Gamma correction is a mathematical curve that translates computer brightness into human-perceived brightness.

Note

Without gamma correction, the smooth fades between colors would look uneven and unnatural. This is one of the most important steps for a pleasing visual result.

6. Color Distance (The 3D Color Room)

The 3D Room Analogy

"Imagine color as a 3-dimensional room. Red is the length, Green is the width, and Blue is the height. Every color is a specific coordinate in this room. The lamp measures the physical distance between its current color and the new one to decide if you actually moved it."

d
Color Distance
Euclidean
How far apart two colors are in 3D RGB space
Δ
Threshold
Custom
Minimum distance to trigger a color change
t
Transition
ms
Time to fade between old and new color

If the distance is very small, the lamp ignores it (preventing flickering from sensor noise). If the distance is large, it knows you moved the lamp to a new surface and begins the transition.

7. Smooth Transitions (Lerping)

If the lamp instantly snapped from red to blue, it would look jarring and cheap. Instead, it uses Linear Interpolation (Lerping for short).

Frame 1

100% Old

Frame 10

66% Old + 33% New

Frame 20

33% Old + 66% New

Frame 30

100% New

The lamp calculates the difference between its current color and target color, takes a tiny step toward the target, pauses for a fraction of a second, takes another step, and repeats. This creates a beautiful, smooth fade that feels almost organic.

Try It!

Try changing the lerp speed in the code! A slower lerp (more steps) creates a dreamier fade. A faster lerp (fewer steps) creates a more responsive, reactive lamp.
💡

The Full Pipeline

Auto-Range → Trimmed Mean → Black Level Correction → Saturation Boost → Gamma Correction → Color Distance Check → Lerp Transition → Repeat!