Euclidean Rhythms
Euclidean rhythms are generated by distributing a number of hits as evenly as possible across a number of steps. This algorithm produces many traditional rhythms from around the world.
The Euclidean Algorithm
Section titled “The Euclidean Algorithm”Given n hits and k steps, the Euclidean algorithm spaces the hits as evenly as possible. For example, 3 hits over 8 steps produces: x . . x . . x .
This is the Cuban tresillo rhythm, found in many styles of music.
Basic Syntax
Section titled “Basic Syntax”Use parentheses after a note to apply Euclidean rhythm:
// note(hits, steps)[C4(3,8)] // C4 with 3 hits over 8 steps[bd(3,8)] // Kick drum with tresillo rhythmThe note plays on the generated hit positions and rests on the others.
With Rotation
Section titled “With Rotation”Add a third parameter to rotate the pattern:
// note(hits, steps, rotation)[C4(3,8,2)] // Same pattern rotated by 2 steps[bd(3,8,1)] // Tresillo starting on second hitRotation is a left shift of the hit pattern. All hit/rest positions maintain their relative spacing, but the whole pattern shifts leftward by rotation steps — positions that shift off the left wrap to the right.
Here is (3,8) at different rotations:
| Rotation | Pattern | Onset positions |
|---|---|---|
| 0 | x . . x . . x . | 0, 3, 6 |
| 1 | . . x . . x . x | 2, 5, 7 |
| 2 | . x . . x . x . | 1, 4, 6 |
| 3 | x . . x . x . . | 0, 3, 5 |
Layering rotations of the same pattern creates interlocking rhythms:
use "std/instruments" { Sampler, Kit };
let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
// Three tresillo rotations interlockingdrums << [bd(3,8,0), sd(3,8,2), hh(3,8,5)];PLAY;Creating Euclidean Patterns
Section titled “Creating Euclidean Patterns”There are three equivalent ways to write Euclidean patterns.
Inline Notation
Section titled “Inline Notation”Use parentheses directly after a note or sample inside []:
[C4(3,8)] // 3 hits, 8 steps[bd(5,8,2)] // 5 hits, 8 steps, rotation 2The euclid() Function
Section titled “The euclid() Function”Create Euclidean patterns with the standalone function:
euclid(3, 8, [C4]) // 3 hits, 8 steps, source patterneuclid(3, 8, [C4], 2) // With rotationThe .euclid() Method
Section titled “The .euclid() Method”Or use it as a method on any pattern:
[C4].euclid(3, 8) // 3 hits, 8 steps[C4].euclid(3, 8, 2) // With rotationSyntax Comparison
Section titled “Syntax Comparison”Inline C4(3,8) | Function euclid(3, 8, [C4]) | Method [C4].euclid(3, 8) | |
|---|---|---|---|
| Source | Single element | Any pattern | Any pattern |
Inside [] | Yes | No | No |
| Multi-note source | No | Yes | Yes |
| Chaining | With modifiers | Standalone | With methods |
These are equivalent:
[C4(3,8)]euclid(3, 8, [C4])[C4].euclid(3, 8)Classic Euclidean Rhythms
Section titled “Classic Euclidean Rhythms”Many traditional rhythms are Euclidean:
| Pattern | Hit pattern | Name | Origin/Style |
|---|---|---|---|
(2,3) | x x . | — | Various |
(3,4) | x x x . | Cumbia | Colombian |
(2,5) | x . x . . | Khafif-e-ramal | Persian |
(3,7) | x . x . x . . | Aksak | Turkish |
(3,8) | x . . x . . x . | Tresillo | Cuban, many styles |
(5,8) | x . x x . x x . | Cinquillo | Cuban, Brazilian |
(4,12) | x . . x . . x . . x . . | — | Various |
(7,12) | x . x x . x . x x . x . | West African bell | Traditional African |
(5,16) | x . . x . . x . . x . . x . . . | Bossa nova | Brazilian |
(7,16) | x . . x . x . x . . x . x . x . | Samba | Brazilian |
Key Patterns in Detail
Section titled “Key Patterns in Detail”Tresillo (3,8)
Section titled “Tresillo (3,8)”x . . x . . x .Onsets at positions 0, 3, 6 — grouping as 3+3+2 eighth notes (long-long-short). This asymmetric grouping is the rhythmic backbone of Cuban son, Afro-Cuban jazz, pop, EDM, and reggaeton. The tresillo is one of the most widely used rhythmic cells in music.
let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
drums << [bd(3,8)]; // Tresillo kickPLAY;Cinquillo (5,8)
Section titled “Cinquillo (5,8)”x . x x . x x .Onsets at positions 0, 2, 3, 5, 6. The cinquillo is a denser complement of the tresillo — it fills in two of the tresillo’s gaps while keeping the same 8-step frame. Found in Cuban contradanza and Brazilian samba patterns.
let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
drums << [rs(5,8)]; // Cinquillo on rim shotPLAY;Samba (7,16)
Section titled “Samba (7,16)”x . . x . x . x . . x . x . x .Seven hits across 16 sixteenth notes — a driving, intricate pattern with onsets at positions 0, 3, 5, 7, 10, 12, 14.
let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
// Samba feeldrums << [bd(7,16), hh*16];PLAY;Multiple Euclidean Patterns
Section titled “Multiple Euclidean Patterns”Combine different Euclidean rhythms for polyrhythmic textures:
// Different euclidean per voice[C4(3,8) D4(5,8)] // Two notes with different rhythms
// Mix euclidean and plain notes[C4(3,8) E4 G4] // C4 has euclidean, E4/G4 are plainMultiple Notes in Source Pattern
Section titled “Multiple Notes in Source Pattern”The source pattern is queried each cycle and its notes are distributed across the Euclidean hit positions. If there are more hits than notes, the notes wrap around:
euclid(3, 8, [C4 E4 G4]) // 1:1 mapping — each note gets one hiteuclid(5, 8, [C4 E4]) // Wraps: C4 E4 C4 E4 C4
// Alternating source changes per cycle[<C4 E4 G4>].euclid(3, 8)Drum Patterns
Section titled “Drum Patterns”Euclidean rhythms create interesting drum patterns:
let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
// Classic polyrhythmdrums << [bd(3,8) sd(2,8) hh(5,8)];
// 3 against 4 against 5drums << [bd(3,16), sd(4,16), hh(5,16)];
// Afrobeat-styledrums << [bd(3,8), sd(2,8), hh(7,8)];Euclidean with Compact Notation
Section titled “Euclidean with Compact Notation”Combine Euclidean patterns with other modifiers:
[bd(3,8)*2] // Euclidean pattern sped up 2x[C4(5,8) D4@2] // Euclidean C4, weighted D4Modifier Order
Section titled “Modifier Order”The order matters — modifiers applied before or after Euclidean give different results:
[C4(3,8)*2] // Euclid then fast: 3 hits played twice as fasteuclid(3, 8, [C4 E4].fast(2)) // Fast before euclid: source doubled, then 3 hits pickedMusical Examples
Section titled “Musical Examples”Afro-Cuban Feel
Section titled “Afro-Cuban Feel”let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
// Cascara pattern approximationdrums << [rs(5,8), bd(3,8), hh*8];PLAY;Minimal Techno
Section titled “Minimal Techno”let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));
// Sparse, hypnoticdrums << [bd(3,16), hh(7,16), sd(2,16,4)];PLAY;Melodic Euclidean
Section titled “Melodic Euclidean”let melody = MidiTrack(1);
// Euclidean arpeggiomelody << [C4(3,8) E4(5,8) G4(7,8)];PLAY;See Also
Section titled “See Also”- Pattern Basics — Pattern fundamentals
- Compact Notation — Other pattern modifiers
- Nested & Parallel Patterns — Layering patterns