3. WFC for Music
A one-dimensional WFC where the tiles are chords, the adjacency rules come from music theory, and everything plays through Web Audio.
A playable chord progression, generated by constraints
The tiles don't have to be grid squares. Here, they're musical elements arranged in a 1D sequence, and the adjacency rules encode which elements can follow which.
Chord progression WFC
The chord tiles (I, ii, iii, IV, V, vi, vii°) have transition rules from music theory. For example, a V chord (the dominant) strongly wants to resolve to I (the tonic); a ii chord naturally leads to V. These rules are the adjacency constraints. WFC explores valid progressions and picks one at random, weighted by how common each chord is.
Drum pattern WFC
A second, independent 1D WFC generates the drum pattern. Tiles are beat types (kick, snare, hi-hat, combinations, rest) with adjacency rules that prevent musically awkward sequences — no two consecutive kicks, for instance. The result is rhythmically coherent even though every generation is unique.
Synthesis
Every sound is generated in real time using the Web Audio API — no
audio files. Chord pads use triangle-wave oscillators; the melody uses sines; the bass
uses a sawtooth; and drums are synthesised from sine sweeps (kick) and filtered noise
(snare and hi-hat). Notes are scheduled with sample-accurate timing via
AudioContext.currentTime.
Why WFC for music?
Music is fundamentally a constraint-satisfaction problem: notes must fit the key, chords must follow harmonic rules, rhythms must cohere. WFC is a natural fit because it generates sequences that satisfy local constraints while remaining globally unpredictable — exactly what makes music interesting.