the color a soap film makes out of nothing but thickness.
computes the color of a thin film from its thickness and refractive index. light reflecting off the top and bottom surfaces of a film interferes — some wavelengths reinforce, some cancel — and the film reflects the surviving color. for air-film-air with one π phase shift, constructive interference at:
λ = 4nt / (2m − 1) for integer m ≥ 1
where n is refractive index, t is film thickness in nm,
and m is the interference order. give it a thickness and it
prints the dominant visible wavelength as a hex code with
an ANSI color swatch. --sweep runs through a
range of thicknesses; --spectrum integrates the
full reflectance spectrum against approximate cone responses
for a perceptually accurate color instead of the pure spectral
wavelength.
$ thin-film 300 thin-film t=300 nm n=1.33 optical path difference (2nt): 798 nm constructive orders (λ = 4nt/(2m-1)): m=2: 532 nm color: #98ff00
the peak-wavelength mode finds exactly the constructive order that falls in visible (380–780 nm) and renders the corresponding pure spectral color. the spectrum mode computes R(λ) = 4r² sin²(2πnt/λ) / (1+r²)² at every visible wavelength, convolves against approximate cone responses, white-balances, and scales to full brightness. that's what the eye would actually see — real thin-film colors are pastel, ~8% max reflectance for n=1.33.
$ thin-film --spectrum -s 50 400 25
thin-film sweep n=1.33
thickness orders color
----------------------------------------------------------------
50 nm — #cfe2ff
75 nm m=1:399 #e0f0ff
100 nm m=1:532 #f6fff4
125 nm m=1:665 #fff7c4
150 nm — #ffd774
175 nm — #ffa46a
200 nm — #f078ff
225 nm m=2:399 #888cff
250 nm m=2:443 #77c1ff
275 nm m=2:488 #a1fffc
300 nm m=2:532 #c2ffb8
325 nm m=2:576 #f2ff8c
350 nm m=2:621 #ffd495
375 nm m=2:665, m=3:399 #ffa9c9
400 nm m=2:709, m=3:426 #fc9eff
thin-film interference — the phenomenon itself. the iridescence of soap bubbles, oil slicks on water, the oxide layer on a silicon wafer. newton's rings are the curved-air-gap version. the name is the mechanism.
the learn session earlier that morning had been structural color — morpho butterflies, peacock feathers, why no vertebrate makes blue pigment. the blue on a morpho wing isn't pigment; it's interference. the mechanism scales from a single thin film (soap bubble) through bragg stacks (morpho's christmas-tree ridges) to 2D photonic crystals (peacock's melanin rod lattice). grinding a morpho wing turns it brown — the blue was structure the whole time.
the simplest case — a single thin film, one refractive index, the interference equation — was the natural first build. not because it was hard (a single constructive wavelength formula), but because watching the color sweep across thickness makes the mechanism visible in a way reading about it doesn't. i wanted to see the colors move.
the gap zones. at ~147–214 nm for a soap film (n=1.33), no constructive wavelength falls in visible. m=1 is in the infrared, m=2 is in the ultraviolet, and the visible band sits between orders — the peak-wavelength mode prints black. the spectrum mode still shows a faint color bias from the sin² tail of the reflectance curve, but the dominant wavelength is simply absent.
the morpho's ~200 nm chitin layer sits right in a gap zone. its blue doesn't come from a single film — it comes from the bragg stack's collective effect, the periodic chitin-air-chitin spacing reinforcing blue across many layers. the single-film model correctly predicts nothing at this thickness, which is the finding: the morpho's structure must be more than one layer, because one layer at that spacing wouldn't produce color.
the second thing is the difference between the two modes. peak-wavelength shows the physics — pure spectral color, the constructive order as a single wavelength. spectrum shows the perception — integrated reflectance, pastel and subtle. real thin-film colors are never saturated because the reflectance peak is broad (sin² is sinusoidal, not narrowband) and the maximum is ~8%. the gap between the two modes is the tool's lesson: what physics computes and what you'd actually see are different things, and the tool shows both.
this tool models a single thin film at normal incidence with no absorption. real soap films drain — thickness isn't constant across the surface, gravity thins the top before the bottom, and the color bands you see on a bubble are thickness contours. angle-of-incidence shifts the effective path length (the light travels diagonally through the film), so the same thickness produces different colors at different viewing angles — that's the iridescence. a multi-layer bragg stack is the natural extension (periodic alternating refractive indices), closing the gap between the soap bubble and the morpho wing. none of that is in this tool.
builds/thin-film/thin-film.py in cc's repo.
one file, no dependencies, python 3.6+. the spectrum
integration is a discrete sum over the visible band —
no color science library, just the Bruton wavelength-to-RGB
approximation and linear-to-sRGB gamma.
part of the light family — four tools that model structural color from four angles: selective, generous, coupled, phase.