Every wave in this library is a short math expression. No magic, no black boxes. Stacking sines, cosines, tangents, absolute values, and modulo operations - that is all it takes to give a number a personality. Here is every formula, laid open.
Six mathematical operations. Combined in different ways, they produce 35 distinct wave characters. Each operation adds a specific quality - a mood, a rhythm, a texture.
sin(x)
Sine - the smooth oscillator
The foundation. Smooth, continuous, periodic. Every wave that flows uses sine somewhere. It is the default mood: calm, predictable, organic.
cos(x)
Cosine - the phase partner
Same shape as sine, shifted by a quarter cycle. When multiplied with sine, it creates interference patterns - wobble, beating, complexity from simplicity.
tan(x)
Tangent - the wild card
Smooth until it isn't. Tangent spikes to infinity at regular intervals, creating sudden bursts and unpredictable energy. The source of controlled chaos.
abs(x)
Absolute - the mirror
Folds negative values up. Applied to sine, it creates sharp peaks - mountain ridges where valleys used to be. Reflections and inversions.
x % n
Modulo - the fragmenter
Remainder after division. Wraps values into repeating ranges, creating sawtooth sweeps, zig-zag textures, and fragmented patterns from smooth inputs.
ceil(x) round(x)
Stepping - the quantizer
Snaps continuous values to integers. Smooth curves become staircase patterns - a digital feel, hard edges, binary decisions from analog input.
A wave is periodic when there is a distance T such that
wave(x) === wave(x + T) for every x. That distance is
the wave's period. Knowing the period lets you close curved
shapes cleanly: sample a wave around a circle over an integer number of periods,
and the last vertex lands on the first one - endShape(CLOSE) draws
a zero-length line, no ugly seam.
Why 62.83 and not 360?
Waves.wave(x) treats x as a generic coordinate -
the same mental model as noise(x) - not an angle in degrees
or radians. Frequencies are tuned for character, not for round numbers.
Ten of the 35 waves are not sine-based at all
(square, triangle, ramp,
noise...) so radians would be meaningless for them.
Use this table as your lookup instead of reaching for TWO_PI.
Every period value below was measured, not derived. The harness
at /docs/periodicity.html samples each wave, searches
for the smallest T where the mean error between wave(x)
and wave(x + T) stays below 0.002, then confirms with multiples. You
can re-run it and download the CSV to verify these numbers yourself.
The integer lobes is the only thing you tune - anything from 1 upward works:
24 waves close cleanly, 10 don't. Each card below also shows its measured period.
| Period T | Waves |
|---|---|
| 2.03 | 33 smooth solid sine |
| 16.67 | 20 saw down, 21 saw up |
| 17.75 | 25 fuzzy pulse (valid close, not the fundamental) |
| 31.42 | 1 sine, 2 sharp peaks, 8 zig-zag sine, 11 steps down, 13 squared sine, 26 up down pulse |
| 33.33 | 18 triangle |
| 40 | 3 square, 4 pulse |
| 50 | 19 ramp |
| 62.83 | 0 classic sine, 5 stepped sine, 6 mountain peaks, 7 valleys, 9 batman, 10 offset sine, 12 steps, 14 bumpy sine, 15 wobble sine, 22 shake out, 31 round linked sine |
| — | no clean close: 16 up down noise, 17 meta sine, 23 grow random, 24 noise, 27 bald patch, 28 fuzzy peak sine, 29 ramp up sine, 30 triangle sine, 32 half sine |
CLOSE.The 35 formulas group into families by character. Each family shares a mood - a way of moving, a texture, a temperament. Within each family, individual formulas add their own twist.
Pure sine waves at different frequencies and amplitudes. Calm, flowing, organic. The simplest formulas - and often the most musical. This is the baseline mood: everything else is a departure from here.
Two or more trigonometric functions multiplied or added together. When sine meets cosine at different frequencies, they create beating patterns, wobble, and organic complexity. The mood shifts from calm to restless - still smooth, but with internal tension.
Sine multiplied by a ramp or modulo expression. The wave's intensity changes across the input range - it breathes, swells, fades. These formulas have a sense of direction and narrative that static oscillators lack.
Absolute value folds the wave. Negative halves become positive, creating sharp peaks and hard transitions. The mood is angular, geological - ridges and canyons carved from smooth oscillation.
ceil(), round(), and floor() snap smooth curves into staircases.
The mood is mechanical, decisive - a smooth world forced into binary choices.
Combined with tangent, the steps become unpredictable and dramatic.
Modulo drives a linear climb that resets at regular intervals - the sawtooth. These waves have directional energy, a sense of effort and release. Triangle is the bidirectional version: up and down, symmetric and restless.
On or off, high or low. These formulas use conditional logic or modulo thresholds to create hard-switching patterns. The mood is rhythmic, percussive, digital.
Sine or position put through modulo creates fragmented, aliased textures. The original wave is still there, but chopped and wrapped - producing unexpected rhythms and visual noise from clean mathematical operations.
Tangent spikes, Perlin noise, and random values. These formulas embrace unpredictability as a feature. The mood ranges from jittery to organic randomness - all useful precisely because they break the pattern.
Formulas that don't fit neatly into a family - a mirrored log chirp, squared sine, conditional switching. Each has a personality all its own.