# HG changeset patch # User Robert McIntyre # Date 1328373193 25200 # Node ID cfb71209ddc602c6245886d6a918848c46c4b7b2 # Parent bdca0daa3778b1195eda2312040316cc3bcd1ef2 moved touch-debug view to touch.org diff -r bdca0daa3778 -r cfb71209ddc6 org/test-creature.org --- a/org/test-creature.org Sat Feb 04 09:11:42 2012 -0700 +++ b/org/test-creature.org Sat Feb 04 09:33:13 2012 -0700 @@ -110,29 +110,6 @@ ;; these are the functions that provide world i/o, chinese-room style - - - -(defn gray-scale [num] - (+ num - (bit-shift-left num 8) - (bit-shift-left num 16))) - -(defn debug-touch-window - "creates function that offers a debug view of sensor data" - [] - (let [vi (view-image)] - (fn - [[coords sensor-data]] - (let [image (points->image coords)] - (dorun - (for [i (range (count coords))] - (.setRGB image ((coords i) 0) ((coords i) 1) - (gray-scale (sensor-data i))))) - - - (vi image))))) - (defn debug-vision-window "creates function that offers a debug view of sensor data" [] @@ -172,8 +149,8 @@ creature (doto (load-blender-model thing) (body!)) - touch-nerves (touch! creature) - touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves) + touch (touch! creature) + touch-view (view-touch) vision-data (vision! creature) vision-debug (map (fn [_] (debug-vision-window)) vision-data) me (sphere 0.5 :color ColorRGBA/Blue :physical? false) @@ -245,9 +222,7 @@ (prop-debug (prop)) - (dorun - (map #(%1 (%2 (.getRootNode world))) - touch-debug-windows touch-nerves)) + (touch-view (map #(% (.getRootNode world)) touch)) (dorun (map #(%1 (%2 world)) diff -r bdca0daa3778 -r cfb71209ddc6 org/touch.org --- a/org/touch.org Sat Feb 04 09:11:42 2012 -0700 +++ b/org/touch.org Sat Feb 04 09:33:13 2012 -0700 @@ -300,6 +300,35 @@ (filter #(isa? (class %) Geometry) (node-seq creature))))) +(defn gray-scale + "Create a gray RGB pixel with R, G, and B set to 'num" + [num] + (+ num + (bit-shift-left num 8) + (bit-shift-left num 16))) + +(defn view-touch + "Creates a function which accepts touch sensor-data and displays it + as BufferedImages in JFrames." + [] + (let + [windows (atom []) + display-single-touch + (fn + [[coords sensor-data] display] + (let [image (points->image coords)] + (dorun + (for [i (range (count coords))] + (.setRGB image ((coords i) 0) ((coords i) 1) + (gray-scale (sensor-data i))))) + (display image)))] + (fn [data] + (if (> (count data) (count @windows)) + (reset! windows (map (fn [_] (view-image)) + (range (count data))))) + (dorun (map display-single-touch data @windows))))) + + #+end_src