Empirical measurement of each wave's period - the x-distance over which
Waves.wave(x) repeats itself. Used to close curved shapes
cleanly: if the total x-sweep is an integer multiple of the period,
endShape(CLOSE) draws a zero-length line.
Method
Each wave is sampled via Waves.wave(x, { wave: idx, t: 0 }) - no amplitude, no range, default [-1, 1] output.
Determinism check: call wave(x) twice at the same x. If results differ, the wave is marked non-deterministic (p5's random() advances internal state).
Period search: for candidate T from 0.5 to 200 (step 0.01), compute mean absolute difference between wave(x) and wave(x + T) at 80 sample points in x ∈ [10, 110]. Smallest T where mean error < 0.002 AND multiples 2T, 3T also match is the detected period.
Close-error: for the detected period T, report |wave(10) - wave(10 + T)| as a final sanity check.
If no T passes within [0.5, 200], the wave is marked non-periodic (or quasi-periodic if the minimum error was low but not low enough).
Ready.
#
Name
Algorithm
Period
wave(10)
wave(10 + T)
|Δ|
Verdict
Verdicts:
periodic - stable period found, error below 0.002 at T, 2T, 3T
quasi-periodic - near-match found but not exact (e.g. incommensurate frequencies)
non-periodic - no match within search range (log, growing amplitude, Perlin)
non-deterministic - wave(x) varies between calls at the same x (uses p5 random)