Skip to content

Instantly share code, notes, and snippets.

@amiika
Created November 9, 2022 18:51
Show Gist options
  • Save amiika/85e3f0fadcae2b6917c7c9d8652c2835 to your computer and use it in GitHub Desktop.
Save amiika/85e3f0fadcae2b6917c7c9d8652c2835 to your computer and use it in GitHub Desktop.
# Bresenhams Euclidean algorithm in Ruby
def euclidean_bresenham(pulses, steps)
return Array.new(steps,1) if pulses>=steps
previous = nil
rhythm = []
steps.times do |i|
div = ((pulses.to_f / steps) * i).to_i
rhythm.push(div == previous ? 0 : 1)
previous = div
end
rhythm
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment