Three.js Oscilloscope (Waveform & Lissajous Figures)
A glowing CRT oscilloscope in Three.js that draws live Web Audio waveforms with zero-crossing triggering, phosphor persistence and bloom, plus an XY mode tracing Lissajous figures from two oscillators in simple frequency ratios.
Key topics: oscilloscope, waveform visualization, lissajous figures, web audio analyser, three.js audio, time domain
Game Over
What this code does
- Time Domain: `AnalyserNode.getFloatTimeDomainData` gives the most recent 2,048 samples, which the trace draws directly.
- Triggering: the trace starts at the first rising zero crossing, so periodic waves stand still like on a real scope.
- Chords: summed oscillators make interference shapes; a detuned octave slowly "breathes" as the phase drifts.
- XY Mode: channel 1 drives x and channel 2 drives y, so ratios like 3:2 or 5:4 trace closed Lissajous knots that rotate as the phase drifts.
- Silent Mode: until you press Play sound, the same voices are synthesised in JS, so the visuals never need autoplay.
- Controls: mode, waveform, frequency, chord, XY ratio, time per division, persistence and glow.
Related Demos
Continue Learning
JavaScript Implementation
// Oscilloscope: read the analyser's time-domain buffer, trigger on a rising zero crossing
const analyser = audioCtx.createAnalyser(); analyser.fftSize = 2048
const buf = new Float32Array(analyser.fftSize)
function draw () {
analyser.getFloatTimeDomainData(buf)
let start = buf.findIndex((v, i) => i > 0 && buf[i - 1] < 0 && v >= 0) // stabilise the trace
for (let i = 0; i < 1024; i++) positions.setXYZ(i, -6 + i / 1023 * 12, buf[start + i] * 3.6, 0)
positions.needsUpdate = true
}
// XY mode: x = channel 1, y = channel 2 → Lissajous figures when frequencies form simple ratios