Skip to content

Instantly share code, notes, and snippets.

@triss
Created May 25, 2014 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triss/90fbc36f1aff2ba008bb to your computer and use it in GitHub Desktop.
Save triss/90fbc36f1aff2ba008bb to your computer and use it in GitHub Desktop.
euclidean beat sin clojure
(ns clojtest.core)
(defn rotate-left
([coll] (rotate-left 1 coll))
([n coll] (concat (drop n coll) (take n coll))))
(defn euclidean-beat
([hit-length length rotation]
(rotate-left rotation
(euclidean-beat hit-length length)))
([hit-length] (euclidean-beat hit-length 16))
([hit-length length]
(take length
(flatten (repeat (cons 1 (repeat (- hit-length 1) 0)))))))
(defn sum [xs ys] (map (fn [x y] (+ x y)) xs ys))
(reduce sum [(euclidean-beat 3)
(euclidean-beat 3 16 3)
(euclidean-beat 5)
(euclidean-beat 4)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment