Last active
December 20, 2015 22:39
-
-
Save daniel-j-h/6206341 to your computer and use it in GitHub Desktop.
Clojure + Leap Motion Requirements: Appropriate Leap libraries / native deps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns leap-clojure.core | |
(:import (com.leapmotion.leap Controller Listener Pointable)) | |
(:gen-class)) | |
(defn frame-handler | |
"Decides what to do with new frame data from the device" | |
[^Controller controller] | |
(let [frame (.frame controller) | |
box (.interactionBox frame) | |
pointables (.pointables frame)] | |
(doseq [^Pointable pointable pointables | |
:when (.isValid pointable) | |
:let [id (.id pointable) | |
pos (.stabilizedTipPosition pointable) | |
tip (.normalizePoint box pos) | |
x (.getX tip) | |
y (.getY tip) | |
z (.getZ tip)]] | |
(println | |
(format "%d \t %.2f \t %.2f \t %.2f" id x y z))))) | |
(defn make-listener | |
"Dispatches based on device events" | |
[] | |
(proxy [Listener] [] | |
(onFrame [controller] | |
(frame-handler controller)))) | |
(defn handle-interaction | |
"Interacts with the user until a newline is received" | |
[] | |
(let [controller (Controller.) | |
listener (make-listener)] | |
(.addListener controller listener) | |
(read-line) ;; block on user input | |
(.removeListener controller listener))) | |
(defn -main [& args] | |
(println "Ready!") | |
(handle-interaction) | |
(println "Bye!")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject leap-clojure "0.1.0-SNAPSHOT" | |
:description "Clojure + Leap Motion" | |
:url "https://gist.github.com/daniel-j-h" | |
:license {:name "MIT License" | |
:url "http://www.opensource.org/licenses/mit-license.php"} | |
:min-lein-version "2.0.0" | |
:repl-options {:prompt (fn [ns] (str *ns* " λ "))} | |
:global-vars {*warn-on-reflection* true} | |
:plugins [[lein-kibit "0.0.8"] | |
[jonase/eastwood "0.0.2"]] | |
:dependencies [[org.clojure/clojure "1.5.1"] | |
[daniel-j-h/leaplib "0.8.0"] | |
[daniel-j-h/leaplib-natives "0.8.0"]] | |
:main leap-clojure.core) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment