## Calculating Euclidean Rhythmns using the Bresenham Algorithm

Recently I started playing with euclidean rhythms and implemented the bjorklund algorithm shown in the paper by Godfired Toussaint in ruby. The implementation isn't really rocket science (actually it's ring accelerator science :-)) but it uses recursive function calls, two arrays, multiple stages, ... and I had the feeling that this is far more complicated than it needs to be. After reading several posts, blogs and papers about the implementations of the algorithm I read somewhere that the algorithm produces the same result as the bresenham algorithm - at first I ignored the sentence and unfortunately I have no idea anymore where I read it but today I implemented a simple version of it an the results I get are the same as my recursive version - or rotations, which is fine because you usually loop over the sequences and are free to choose a starting point - so in case anyone is interested here is my bresenhamish method for calculating euclidean rhythms in ruby - shouldn't be too complicated to port it to different languages

```
def eucledean(k,n)
f = 1.0*n/k
res = Array.new(n,0);
a = 0
k.times do |i|
res[a.to_i] = 1
a += f
end
return res
end
(1..8).each do |i|
print eucledian(i,8)
print "\n"
end
```

and this are the results I get for the 8 possible rhythms with 8 steps

```
[1, 0, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 1, 0, 0, 0]
[1, 0, 1, 0, 0, 1, 0, 0]
[1, 0, 1, 0, 1, 0, 1, 0]
[1, 1, 0, 1, 1, 0, 1, 0]
[1, 1, 1, 0, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 1, 1, 0]
[1, 1, 1, 1, 1, 1, 1, 1]
```

## See also:

creating midifiles using ruby

New Track - Harmonic

Time Perception

New Track - Time Perception