Rhythm Generation With an Euclidian Algorithm
Posted: October 26th, 2008 | Filed under: Music, Graphics, Video, Personal | Tags: euclidian, generation, music, rhythm | 18 Comments »The original post on this is at wesen’s where you can pick up the idea and hear some samples. In this post I simply show the Ruby implementation of the algorithm. It doesn’t work with lists, but rather does simple math to achieve the same effect.
The idea of distributing pulses is curious. It lacks one important aspect though — shifting. Currently all patterns start with “1″. Thanks wesen, for sharing this. Here comes the Ruby version.
def distribute(pulses, steps)
pauses = steps - pulses
per_pulse = (pauses / pulses).to_i
remainder = pauses % pulses
rhythm = []
pulses.times do |pulse|
rhythm << 1
per_pulse.times { rhythm << 0 }
rhythm << 0 if pulse < remainder
end
return rhythm
end
# 1 0 0 1 0 0 1 0
puts distribute(3, 8).inspect
pauses = steps - pulses
per_pulse = (pauses / pulses).to_i
remainder = pauses % pulses
rhythm = []
pulses.times do |pulse|
rhythm << 1
per_pulse.times { rhythm << 0 }
rhythm << 0 if pulse < remainder
end
return rhythm
end
# 1 0 0 1 0 0 1 0
puts distribute(3, 8).inspect

The Ruby on Rails addict, industrial photographer and amateur electronic music composer. In the mean time I build great web applications, contribute to OSS and help AVAAZ to save Great Barrier Reef.