Skip to content

Instantly share code, notes, and snippets.

@crashingbooth
Created March 5, 2018 01:24
Show Gist options
  • Save crashingbooth/e9f0b7dbec8aecabf13db3663d28480f to your computer and use it in GitHub Desktop.
Save crashingbooth/e9f0b7dbec8aecabf13db3663d28480f to your computer and use it in GitHub Desktop.
Bresenham Implementation of Euclidean Rhythm Generator
func bresenhamEuclidean(onsets: Int, pulses: Int) -> [Int] {
    let slope = Double(onsets) / Double(pulses)
    var result = [Int]()
    var previous: Int? = nil
    for i in 0..<pulses {
        let current = Int(floor(Double(i) * slope))
        result.append(current != previous ? 1 : 0)
        previous = current
    }
    return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment