Street light
A line-drawn street with an LED street light: change its height, tilt and optic and watch where the light lands.
street-light/street-light.tsx- Road 69%
- Pavements 19%
- Behind pole 2%
- Gardens 10%
- Houses 0%
- Sky 0%
- BUG
- B1 U0 G1
- Road avg
- 17 lx
- Road peak
- 40 lx
- Bedroom window
- 0 lx
The live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.
The choices it offers, each value drawn live and the default marked, with how to pick one.
When to use
- Explaining a physical trade-off by letting the reader move it: how pole height, tilt and optic change where the light lands.
- A long-form article or report on lighting, light pollution or street design, where one interactive figure carries the argument.
- Teaching the vocabulary of a field (BUG rating, lux, isolux lines) next to the picture it describes, so every number has a place.
- A figure that should read as a drawing first: hairlines, captions and small tracked capitals, in a dark or a light scheme.
When not to use
- Real lighting design or compliance work. The model is a teaching one; use photometric software fed with the luminaire’s IES file.
- Reporting measured data. Use a chart or a table of the readings, not a simulation that looks like one.
- A dense dashboard tile. The figure needs about 600 px to read; a small stat card or a sparkline fits better.
- Pages with many instances: each holds a WebGL context. One figure per page, or a static image for the rest.
Reading the numbers
- BUG rates the light that goes Back (behind the pole), Up (into the sky) and the Glare at high angles, each from 0 (least) to 5.
- Lux is light falling on a surface: the road’s average and peak, and the bedroom window across the garden.
- The bar shares the flux out between road, pavements, behind the pole, gardens, houses and sky; the legend gives each share in numbers.
- All of it is a teaching model, calibrated per optic and carried between its lines; it is not a photometric calculation.
One per page
Each instance holds a WebGL context and paints only while something moves. Browsers keep a small number of contexts alive, so use one live figure per page and still images for the rest. Without WebGL the drawing stays, lit by a plain gradient pool, and the panel still works.
Each one drawn with the component itself, used well or badly.
The figure’s own words are fixed, apart from its number: the name, the panel’s labels and the hint. What you write is the text around it.
- Say which settings it opens on and why:
An asymmetric optic on an 8 m pole, head level. - Number it in step with your text: the caption reads
Fig 1unless you passcaption, such asFig 3, and refer to it by that number. - Use the units it shows: metres for height, degrees for tilt, lux (
lx) for light; spell out BUG once. - Tell the reader what to try:
Drag up on the figure to raise the pole, or press 2 for the wide optic.
You can add this component with the shadcn CLI or by hand:
Into components/street-light of any React project, with no setup:
npx shadcn@latest add https://brunodelorence.com/r/street-light.json- Copy the component files
Copy these files into one folder of your project, keeping their relative imports together, or download them as a ZIP:
- Import it
As shown under Usage, below.
Either way it needs React 19 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.
Usage
import { StreetLight } from './street-light';export function LightingFigure() { return <StreetLight defaultOptic="wide" defaultTilt={10} defaultLuxMap autoplay={false} />;}Each state below is a live instance, locked so you can study it.
The pieces it is built from, each with its measurements read live.
A technical figure of a terraced street at night, drawn as an axonometric line diorama and lit by a shader through the same camera. Pick a narrow, wide or asymmetric optic, drag the pole’s height and the head’s tilt, and the pool on the road, the wash on the walls and the glow in the air move with it, with the BUG rating, road lux and the lux on a bedroom window computed from the same model. A lux map turns the light into false colour with isolux lines.
- The street is a small model in metres, seen through one parallel camera (turned 32° about the vertical, looking down 32°). The drawing is SVG: every solid is filled with the paper colour and painted far to near, so hidden edges are covered rather than left out; faces take a tone by what they face and edges are 0.6 px hairlines in four inks that never scale.
- The light is a WebGL canvas laid over the drawing, using the same camera. It draws the faces the camera sees as triangles with a depth test, so each pixel knows the true point and normal it shows, and lights it by inverse square and cosine (I · cos θ / d²) from the optic’s candela distribution, with shadows from the pole, the pillar, the walls, the shed and the tree.
- The optics are distributions in the head’s frame: a round narrow spot, a wide one that stays nearly even out to 55°, and an asymmetric one given as a candela table (intensity over a grid of directions, read bilinearly, as photometric files give it) with a batwing along the street and a steep cut-off on the house side. Tilting the head turns the frame, so the house side of a wide optic rises above the horizon and lights the air over the roofs.
- The air glows: light scattered towards the eye is summed along each pixel’s ray through the beam below the head (faint at the lens, growing as the beam drops), plus a few soft glows integrated in closed form. The warm tone is rolled off (1 − e^−x) and dithered by about one level so the soft gradients never band.
- The lux map is magma false colour on a log scale from 0.5 to 100 lx, with isolux lines at 1, 2, 5, 10, 20, 50, 100 and 200 lx kept one pixel wide by their screen-space derivative. With the map off, the same lines stay as a faint trace.
- On a dark scheme the canvas is screen-blended, so it can only add light. On a light one it is ink on paper: the colour each pixel should show is chosen first (an amber tint for light, the same ramp for the map, dark ink for the isolux lines) and the ink that turns the paper into it is written.
- The panel’s numbers (where the flux goes, the BUG rating, road and window lux) are a calibrated table per optic, over pole heights for the asymmetric optic and over tilts for the other two, interpolated with a monotone cubic; off those lines the model carries the change (shares and rating by its difference, lux by its ratio), with the flux traced through a fixed set of directions from the lens. A change of optic cross-fades the three distributions over a second and a half, so the picture, the bar and the numbers slide together.
- Painting runs only while something moves. Without WebGL the drawing stays, lit by a plain gradient pool; under reduced motion the lamp is on from the start, changes are instant and the demo never runs.
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOptic | 'narrow' | 'wide' | 'asymmetric' | 'asymmetric' | The optic in the head when it mounts. |
defaultHeight | number | 8 | The pole’s height in metres, from 5 to 12. |
defaultTilt | number | 0 | The head’s tilt in degrees, from 0 to 25: it lifts the head’s house side. |
defaultLuxMap | boolean | false | Starts with the lux map on. |
onChange | (settings: { optic, height, tilt, luxMap }) => void | — | Called with the settings whenever the reader or the demo changes them. |
autoplay | boolean | true | While on screen and untouched, a demo pointer plays with the controls. It never runs under reduced motion. |
colorScheme | 'light' | 'dark' | 'system' | — | Light or dark colours, or the reader’s. Without it, the component follows the page’s color-scheme. |
className | string | — | A class for the root, to size or place it. |
Keyboard
- Height and tilt are native range inputs, moved with the arrow keys in steps of 0.1, their values spoken in metres and degrees.
- The optics are native radios in a group named
Optic: the arrow keys move between them, and keys 1, 2 and 3 pick one. - The lux map is a button named
Lux mapwitharia-pressed; L toggles it too. - Keys 1–3 and L are heard only while focus is inside the component, so they never fire elsewhere on the page (WCAG 2.1.4, Character key shortcuts).
Pointer
Dragging on the figure only repeats what the sliders do, and a slider can be set by pressing on its track, so no setting needs a drag (WCAG 2.5.7, Dragging movements).
The picture and the numbers
- The figure is one image (
role="img") whose label states the height, the tilt, the optic and whether the lux map is on, with the map’s colour scale in words when it is. - The summary line (rating, road share, sky share, window lux) is read out in a polite live region 600 ms after the reader’s settings rest (WCAG 4.1.3, Status messages). The demo’s changes are not read out.
- The bar is hidden from screen readers; the legend names every zone with its share, so the colours are never the only cue (WCAG 1.4.1, Use of colour). The lux map’s colours are read by the key drawn over the figure, from 0.5 to 100 lx, and by the numbers in the panel.
Contrast
In both schemes the labels, values, legend and hint hold at least 4.5:1 on the surface (WCAG 1.4.3, AA), and the sliders’ tracks and thumbs at least 3:1 (WCAG 1.4.11, AA). The optic cards and the lux map button are named by their words; their picked state is a near-black or near-white edge.
Motion and the demo
Under reduced motion the lamp is on from the start, changes are instant and the demo never runs. Otherwise the reader’s first press, key, scroll or focus inside the component stops the demo for good (WCAG 2.2.2, Pause, Stop, Hide). Next to long text, pass autoplay={false}.
In this build
- Height and tilt are native range inputs with their values spoken in metres and degrees; the optics are a radio group, and the lux map is a toggle button with aria-pressed.
- Keys 1, 2 and 3 pick an optic and L turns the lux map on or off, anywhere in the component.
- The figure is an image with a label that states the pole’s height, the tilt and the optic; the drag on it only repeats what the sliders do.
- The summary line (rating, road share, sky share, window lux) is read out politely once the settings rest, not at every step of a drag.
- Under reduced motion the lamp is on from the start, changes are instant and the demo never runs. The demo pointer is hidden from screen readers.
The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useEffectEvent, useId, useRef, useState, type PointerEvent as ReactPointerEvent,} from 'react';import { project, SCALE, VIEW } from './camera';import { DemoPointer, runDemo, type Point } from './demo-pointer';import { LightLayer, poleOf } from './light';import { OPTICS, ZONES, lampOf, ratingText, type Lamp, type Mix, type Optic, type Rating,// Copyright (c) 2026 Bruno Delorence. MIT License./* * The camera of the figure: one parallel (orthographic) projection, shared by the SVG drawing and * the light shader, so a lit pixel lands exactly on the line it belongs to. * * The world is in metres: x runs along the street (to the right and down the page), y across it * (towards the houses, up the page), z up. The camera turns YAW about z and looks down at PITCH; * a metre is SCALE units of the figure's viewBox, and the world's origin sits at ORIGIN. */export type Vec3 = readonly [number, number, number];/** The figure's viewBox, in its own units (CSS px at 1080 px wide). */export const VIEW = { width: 1080, height: 896 } as const;const deg = Math.PI / 180;export const YAW = 32 * deg;export const PITCH = 32.04 * deg;export const SCALE = 21.17;export const ORIGIN = [63.3, 583.28] as const;const cy = Math.cos(YAW);const sy = Math.sin(YAW);// Copyright (c) 2026 Bruno Delorence. MIT License./* * The diorama as solids, in metres: a street block on a rounded plinth (a road sunk between two * pavements, front gardens behind low walls), a terrace of three houses, a shed, a tree, a feeder * pillar and the street light, with a tray of LED modules, a plate and a scale bar on the * plinth's front. The same faces feed both layers of the figure: * * - The drawing (SVG): every solid is filled with the paper colour and painted far to near, so * what is behind is hidden by being covered; no hidden line is ever drawn. Faces take a tone by * what they face, and edges are hairlines in four inks (hi, mid, lo, faint). * - The light (WebGL): the faces the camera sees, as triangles with a surface kind; the shader * lights each pixel from its true position and normal, with a depth test. * * Only the pole and its head move (height and tilt), and the picked LED module lifts out of its * tray; everything else is built once. */import { TOWARD_VIEWER, depthOf, project, type Vec3 } from './camera';export type Fill = | 'deck' | 'side' | 'well'// Copyright (c) 2026 Bruno Delorence. MIT License./* * The light: three optics as candela distributions, and what they do to the street, in lux. * * - Illuminance on a surface is E = I(direction) · cos(incidence) / distance², from the lens. On * level ground under an untilted head that is the familiar I · cos³γ / h². * - Directions are read in the head's frame: its axis (straight down when untilted), the street * (x) and its throw side (towards the near pavement, -y). Tilting the head turns that frame * about the street, so the house side of a wide optic rises above the horizon. * - The narrow optic is a spot on its own swivel: tilting the head steers its aim along the * pavement, so its pool slides rather than stretches. * - The asymmetric optic is two profiles multiplied: along the street a batwing (strongest near * 60° to carry the light down the road), across it a lobe thrown a little forward with a steep * cut-off on the house side. * - The same formulas run in JS (the numbers in the panel) and in the light shader (the picture); * GLSL below mirrors them line for line. */import type { Vec3 } from './camera';import { BANDS, BLOCK, HOUSES, NEAR_END, POLE, ROAD_Z } from './scene';export const OPTICS = ['narrow', 'wide', 'asymmetric'] as const;export type Optic = (typeof OPTICS)[number];// Copyright (c) 2026 Bruno Delorence. MIT License./* * What the panel says: where the flux goes, the BUG rating, and road and window lux. * * The figure's numbers are a calibrated table, not raw physics. Each optic has its readings at * the states the figure is built around (the asymmetric optic over pole heights, untilted; the * wide and narrow ones over tilts, on an 8 m pole), and the numbers in between are interpolated * smoothly (monotone cubic, so they never overshoot a reading). Away from those lines the * physics in optics.ts carries the change: shares and the rating move by the model's difference, * lux by its ratio. * * While optics cross-fade, the numbers cross-fade by the same weights; the rating letters mix on * a log scale (each step of a BUG band stands for several times more stray light), so a little of * a wide optic's uplight still shows as U2 or U3 until it has nearly gone. */import { OPTICS, ZONES, illuminance, lampOf, report, roadStats,// Copyright (c) 2026 Bruno Delorence. MIT License./* * The light layer: a WebGL canvas laid exactly over the drawing, seen through the same camera. * * It draws the faces the camera sees as triangles, with a depth test, so every pixel knows the * true point and normal it shows. For that point the fragment shader works out, from the optics: * * - the illuminance (I · cos incidence / d²), with shadows from the pole, the pillar, the walls, * the houses, the shed and the tree, tested against boxes along the ray to the lens; * - the light as the eye sees it: a warm tone on the dark scheme (1 − e^(−c·E), so bright pools * roll off instead of clipping), or the lux map: false colour on a log scale from 0.5 to * 100 lx, with isolux lines at 1, 2, 5, 10, 20, 50, 100 and 200 lx kept one pixel wide by * their screen-space derivative; * - the haze in front of it: light scattered by the air between that point and the eye, * integrated along the pixel's ray with equiangular samples about the lens (so the glow * round the head is smooth with few samples), and shadowed by the houses. * * On a dark scheme the canvas is screen-blended, so it can only add light to the drawing. On a * light one it is ink: the colour each pixel should show over the paper is chosen first, then the * ink that turns the paper into it, so light reads as warm tint and saturated colour. */import { CAMERA, TOWARD_VIEWER, VIEW } from './camera';// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends * the step in progress at once: its promise rejects, which ends the script right there, and the * pointer fades out. * * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame. * The points of the flight are handed to whoever wants to move along with it (the eye of the * badge, which plays its own animation on the same clock). The arrow and the hand are HTML boxes * that swap by their visibility: a change of style inside an SVG would lay the SVG out again. */export type Point = { x: number; y: number };/** A glide's path and timing, for an animation that plays along with it. */export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };export type Demo = {// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and not once the reader has used it. `take()` hands it to the reader for * good: their first press or key stops the demo until the component mounts again (WCAG 2.2.2). */export function useAutoplay<T extends HTMLElement>() { const ref = useRef<T>(null); const [visible, setVisible] = useState(false); const [reduced, setReduced] = useState(true); const [taken, setTaken] = useState(false); useEffect(() => { const element = ref.current; if (!element) return; let onScreen = false; const update = () => setVisible(onScreen && !document.hidden); const observer = new IntersectionObserver( ([entry]) => {/* Street light (street-light.tsx): a near-black technical figure, "Fig 1", over a panel of controls set in small, tracked monospace capitals. Colours are the tokens below, light-dark(light, dark) where the two differ: the component takes the color-scheme it inherits from the page, or the one its colorScheme prop sets (data-color-scheme). The canvas cannot read tokens, so a hidden probe turns white or black with the scheme and the script repaints when its colour changes. Sizes are the figure's own at about 1080 px wide: 13 px labels tracked 0.1em, 14 to 15 px values. Below 600 px the sliders and the optic cards stack. */.root { /* The stage, and the panel's hairlines. */ --surface: #111; --line: #2a2a2a; --edge: #363636; --edge-strong: #d8d8d8; --track: #626262; /* Words: values, labels, and the dim ones. */ --ink: #f0f0f0; --muted: #828282; --soft: #a8a8a8; /* Where the light goes: one colour per zone. */ --road: #e4c28b;