Wave Visualization: 2D Waves, Interference and Chladni Patterns
To try a wave visualization, start with the change you want to make. Use Wave Equation to disturb a 2D field, Wave Interference to move sources and adjust phase, or Chladni Plate to explore nodal patterns.
This guide connects the controls to the calculation behind each demo. They use three different approaches: a 2D finite difference update, a sum of sine waves, and particles attracted toward a nodal field.
Choose a wave visualization demo
| What to explore | Open the demo | Main controls |
|---|---|---|
| A disturbance spreading across a grid and reaching its edges | Wave Equation | Click or drag, switch boundary mode, Clear |
| Interference between multiple sources | Wave Interference | Add or move sources, Freq, Amp, Phase, display mode |
| Particles gathering near nodes | Chladni Plate | Change n and m, Reset particles |
These are interactive browser demos, with no calibration of length or time to a physical experiment. The numbers below describe the current implementation.
Wave Equation: click to disturb a 2D field
Open Wave Equation and click near the center. The demo adds displacement at that position and draws its propagation. Hold and drag to add displacement along your path.
For a boundary comparison:
- Press Clear to set the current and previous displacement arrays to zero.
- Click once near the center and watch the disturbance reach the edges.
- Switch Reflective / Absorbing.
- Press Clear again, then click at approximately the same position.
Switching the boundary button does not erase the existing wave. Clearing between attempts reduces the influence of the previous input.
Calculate the next displacement from two time levels
For displacement u and wave speed c, the continuous 2D wave equation is:
∂²u/∂t² = c²(∂²u/∂x² + ∂²u/∂y²)The demo uses a 200×200 grid. Its interior update uses the four neighboring cells, the current value, and the previous time level. This excerpt follows the implementation:
const GRID = 200
const C = 0.45
const C2 = C * C
const DAMPING = 0.995
const laplacian =
current[i - 1] + current[i + 1] +
current[i - GRID] + current[i + GRID] - 4 * current[i]
next[i] = (2 * current[i] - previous[i] + C2 * laplacian) * DAMPINGC2 is 0.2025, and the simulation performs three updates per rendered frame. DAMPING multiplies the entire update result. The controls do not set a physical grid spacing and time step for converting the displayed speed into meters per second.
Grid spacing and time step affect the error and stability of finite difference methods. Langtangen and Linge's text introduces that analysis. Conditions derived for an undamped scheme do not by themselves establish the accuracy of this complete, damped demo.
The “Absorbing” label does not mean a non-reflecting boundary
The current Reflective branch copies adjacent interior values onto the boundary. The branch labeled Absorbing leaves the boundary displacement at zero.
A zero-value boundary can also reflect waves. Treat the switch as a comparison of two boundary implementations; it does not provide a perfectly matched layer (PML) or guarantee that a wave exits without reflection.
Wave Interference: change sources, phase, and spacing
Open Wave Interference. It starts with two sources. Drag an existing source to move it, or press an empty area to add one, up to four. With more than two sources, buttons such as -S1 remove them. The source count cannot go below two.
Select Color Map and press Reset, then leave the initial two sources in place. Compare the displayed Phase near 0° with approximately 178°, corresponding internally to 0 and 3.1 radians. At the center, equidistant from the two sources, the waves reinforce each other at 0° and nearly cancel at approximately 178°. After comparing phase, move one source. Change position and phase separately so you can follow which control changes the combined field.
| Control | Range | Meaning in this demo |
|---|---|---|
| Freq | 4–30 | The spatial coefficient that changes wave spacing |
| Amp | 0.2–2 | The amplitude coefficient in each source term |
| Phase | Displayed as 0–approximately 355° | Successive phase offsets for sources after the first, in internal steps of 0.1 radians |
| Color Map / Height Map | Two modes | Show the combined field as color or height |
Rather than advancing a grid from its previous state, this demo evaluates and adds sine waves at each position. Each source contributes:
(Amp / max(1, √distance))
× sin(2π × Freq × distance / canvasWidth − 6 × time + sourcePhase)distance and canvasWidth are screen distances, while time is the animation's internal time. Numbering sources from zero, sourcePhase equals the source index multiplied by Phase: 0 and Phase for two sources, or 0, Phase, and 2×Phase for three.
Freq is not a physical frequency setting in Hz. It changes the spatial coefficient while the time coefficient remains 6. Amp behaves differently in the two display modes. With the same sources at the same time, the common amplitude factor normally cancels during Color Map normalization. Height Map multiplies the normalized field by an additional 30 × Amp, so doubling Amp normally doubles the height relative to its baseline. The special handling of a near-zero combined field is an exception to this normalization behavior.
Reset restores the initial two sources, Freq=12, Amp=1, Phase=0, and animation time=0. It keeps the selected display mode.
Chladni Plate: compare nodal patterns with n and m
Open Chladni Plate and start from n=2, m=3. Change one integer at a time; both controls range from 1 to 6. Reset scatters the particles again and keeps n and m.
Using normalized coordinates x and y, the demo constructs this field:
F(x,y) = cos(nπx)cos(mπy) − cos(mπx)cos(nπy)It attracts 2,000 particles toward regions where F is close to zero. It does not evolve a wave PDE or calculate the response of a physical plate driven at a chosen frequency.
Use different n and m values when comparing distinct nodal patterns. If n=m, the two terms cancel and the entire field is zero. That is not a pattern with more closely spaced nodal lines. Random jitter is still applied to the particles, so a zero field does not mean they stop moving.
The Hz label is the rounded value of 120 × √(n² + m²). With no inputs for material, dimensions, or thickness, it is not a calibrated prediction of a real plate's resonance frequency.
Limits when interpreting the display
These demos explore classical waves and nodal relationships. They do not calculate a quantum wavefunction. The current controls also offer no slits or obstacles, so this guide does not present them as a diffraction experiment.
Computational cost depends on more than grid size. Wave Equation allocates a new Float32Array on each simulation update and ImageData during rendering. Using a TypedArray alone does not establish zero garbage collection or a speed advantage of a particular multiple. This guide provides no measured performance results.
Try changing one control in one demo and connect it to the relevant part of the calculation. To compare patterns produced by reaction and diffusion, continue to the Gray–Scott model guide to controls, feed, and kill.
Go deeper on this topic
Creative Coding
Mathematical simulations, nature visualization, and generative art in the browser
Article 5 of 13 in this series.
Next reads
The N-Body Problem in the Browser — Implementing Gravitational Simulation
Implementation details of gravitational calculations, vector operations, integration methods, and orbit rendering used in the NBody, SolarSystem, and GravityWell components.
Gray–Scott Reaction-Diffusion: Feed, Kill, and Demo Controls
Try four Gray–Scott reaction-diffusion presets, place seeds, and reset the grid. Learn what feed and kill mean and how the demo limits its numerical time step.
Sandpile Model and Self-Organized Criticality — Running the BTW Model in the Browser
Visualizing self-organized criticality in the browser through an implementation of the Bak-Tang-Wiesenfeld sandpile model. Measuring power-law avalanche distributions and the formation of fractal patterns.
Use the topic hub as a map, then continue to the next article in the series. New here? Start at the home hub →