How it works
A textbook ray diagram of a converging lens. The optical axis and the lens are drawn in neutrals, with F and 2F marked on both sides. The object is a small notched flag in the accent colour; drag it along the axis, press beside it, use the keys or one of five place buttons. Three principal rays leave its tip: the parallel ray bends through F′, the central ray passes straight through the centre and the focal ray comes through F and leaves parallel. Where they meet is the image, drawn as the same flag scaled by the magnification: upside down when inverted, dashed with dashed traced-back rays when virtual. A readout gives dₒ, dᵢ (negative for a virtual image) and m = −dᵢ/dₒ, with one sentence for the region the object is in; the place buttons also show that region. An image that falls outside the drawing is announced with a small note in that corner.
Use it for
- Teach the image rules of a converging lens: let learners move the object through 2F and F and see the image change side, size and orientation.
- Explain cameras, projectors and magnifiers as three positions of the same lens, then check the answer with the lens equation in the readout.
Look elsewhere when
- For thick lenses, lens systems or aberrations: this is the ideal thin-lens model with paraxial rays.
Usage
import React, { useState } from 'react'
import { FocalFlagBench } from './FocalFlagBench.jsx'
export function LensLesson() {
const [distance, setDistance] = useState(100)
return (
<FocalFlagBench
distance={distance}
onDistanceChange={(next) => setDistance(next)}
focalLength={40}
labels={{ title: 'Where does the image form?' }}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
distance | number | — | Controlled object distance dₒ in millimetres, rounded to whole millimetres and kept between 0.2 f and 3 f. |
defaultDistance | number | 60 | Starting object distance when uncontrolled, and what Reset returns to in both modes. |
onDistanceChange | (distance, details) => void | — | Called with the new distance and { reason ('press', 'drag', 'tap', 'key', 'place', 'cancel' or 'reset'), region ('beyond', 'at2f', 'between', 'atF' or 'inside'), imageDistance (mm, negative when virtual, null at F), magnification (null at F) }. |
focalLength | number | 40 | Focal length f in millimetres (whole, at least 5). The drawing is in units of f, so only the numbers change. |
labels | object | — | Replaces any built-in text: title, formula, focal ('{f}'), rays (three), marks (four), objectDistance, imageDistance, magnification, distance, valueText ('{d}', '{image}'), help, offView, place, reset, and regions.beyond / at2f / between / atF / inside, each with tab, name, image and note. |
locale | string | 'en' | Language tag for the number readouts. |
className | string | — | Extra class on the card, for example to set its width (30rem by default, never wider than its container). |
Accessibility
- The figure is a slider for the object distance. Left and Right arrows move the flag that way along the axis (Left is farther); Up and Down add or remove 1 mm, Page Up and Page Down 10 mm, Shift with an arrow 10 mm, Home and End go to the nearest and farthest place. Its value text reads the distance and the kind of image, and a description explains the keys.
- The five place buttons are toggle buttons named after their region; the one for the object's current region is pressed. The sentence about the region is a polite live region, so it is read when the region changes.
- Dragging uses pointer capture. A finger on the flag drags it at once; elsewhere on the figure a finger changes nothing until it moves sideways or lifts, so vertical scrolling is not caught. A cancelled gesture restores the distance it started from.
- Colour is not the only key: the legend names each ray, the image repeats the object's shape, and a virtual image is dashed as well as softer.
Motion
After a key, a place button, a tap or Reset, the flag, the rays and the image glide to the new distance for --ds-duration-slow, so crossing F visibly sends the image off to infinity and back. While dragging they follow the pointer directly. With reduced motion every change lands at once.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
FocalFlagBench.jsxfocal-flag-bench.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.







