Visualizations
464 / 500

464 · Illusions

Afterimage

Stare at a surreal landscape, then see full color in a picture that is pure gray.

Each landscape is generated in code, then turned into an adaptor: every pixel goes from linear RGB through XYZ to LMS cone space, the two opponent channels (L minus M, and S minus the mean of L and M) are negated and boosted, and luminance is kept, so the complementary colors line up exactly with the edges of the gray test image. Out of gamut colors are pulled toward gray by bisection on chroma. Stare at the cross while it fills, and when the picture turns gray your tired cones paint the original colors back on, before the real photo fades in. A small model of cone adaptation runs alongside, every cone class at every point adapting with a 4.5 second time constant, and predicts the afterimage you should see by dividing the gray image by that adaptation state.

Try it. Keep your eyes on the cross while the ring fills. New scene (N) generates another landscape, Stare cycles 15, 30 and 8 seconds, Model shows the predicted afterimage as it builds, Space skips to the next phase, and Restart (R) starts staring again.

  • LMS cone space
  • Opponent color inversion
  • Gamut mapping by bisection
  • Von Kries adaptation model

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a negative afterimage demo with JavaScript and the HTML canvas element: I stare at a strangely colored landscape, it turns gray, and I see it in its real colors. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window.
- Generate a simple landscape into an offscreen 480 x 300 ImageData: a blue sky gradient, a sun, green hills and a field of red flower dots. Draw it scaled to cover the canvas.
- Make two more versions of it. The gray version replaces every pixel with its luminance (0.2126 R + 0.7152 G + 0.0722 B, computed in linear light). The inverted version keeps each pixel's luminance but flips its color to the complementary hue.
- Run a timer: show the inverted image with a white fixation cross in the middle for 15 seconds, then the gray image for 8 seconds, then fade in the real colors. Draw a ring around the cross that fills as the seconds pass.

Once that works, make it beautiful:
- Do the inversion in cone space for a stronger effect: convert linear RGB to LMS, form the opponent channels L - M and S - (L + M) / 2, negate them, and convert back. Pull out-of-gamut colors toward gray by searching for the largest chroma that fits.
- Add a New scene button that generates a different landscape, and let me change the stare time.
- Show a small meter of how tired the L, M and S cones are at the cross, building up while I stare.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as a model that predicts the afterimage, more scene types, or a blank white test card instead of the gray picture.
PreviousChange RingingEight bells ring Cambridge and Grandsire: walks through the symmetric group. NextBroad-Nib CalligraphyA dip pen writes italic and uncial letters; thick and thin come from the nib angle.

Related visualizations

  • Through Other EyesType and image A fruit market, a metro map and test plates as dichromats see them.
  • Foveated VisionIllusions What one eye really captures: a sharp fovea, a blurry gray periphery and a blind spot.
  • Color ConstancyIllusions Strawberries under cyan light: not a single red pixel, and they still look red.
  • Lateral InhibitionIllusions Four brightness illusions, each predicted live by a model of retinal ganglion cells.
  • Waterfall IllusionIllusions Stare for twenty seconds, then watch a frozen picture drift the other way.
  • Hybrid ImagesIllusions One picture, two subjects: an owl up close, a cat from across the room.
  • Checker ShadowIllusions Squares A and B are the exact same gray. Move the light and the shadow keeps lying.
  • Hidden 3DIllusions A live magic eye picture: a turning 3D sculpture hidden in colorful noise.
  • Anamorphic MirrorIllusions A wildly warped drawing that a chrome cylinder turns back into a picture.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs