changeset 185:cfb71209ddc6

moved touch-debug view to touch.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 09:33:13 -0700
parents bdca0daa3778
children 21816b27d7c8
files org/test-creature.org org/touch.org
diffstat 2 files changed, 32 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Sat Feb 04 09:11:42 2012 -0700
     1.2 +++ b/org/test-creature.org	Sat Feb 04 09:33:13 2012 -0700
     1.3 @@ -110,29 +110,6 @@
     1.4  ;; these are the functions that provide world i/o, chinese-room style
     1.5  
     1.6  
     1.7 -
     1.8 -
     1.9 -
    1.10 -(defn gray-scale [num]
    1.11 -  (+ num
    1.12 -     (bit-shift-left num 8)
    1.13 -     (bit-shift-left num 16)))
    1.14 -
    1.15 -(defn debug-touch-window
    1.16 -  "creates function that offers a debug view of sensor data"
    1.17 -  []
    1.18 -  (let [vi (view-image)]
    1.19 -    (fn 
    1.20 -      [[coords sensor-data]]
    1.21 -      (let [image (points->image coords)]
    1.22 -        (dorun
    1.23 -         (for [i (range (count coords))]
    1.24 -           (.setRGB image ((coords i) 0) ((coords i) 1)
    1.25 -                    (gray-scale (sensor-data i)))))
    1.26 -
    1.27 -                   
    1.28 -        (vi image)))))
    1.29 -
    1.30  (defn debug-vision-window
    1.31    "creates function that offers a debug view of sensor data"
    1.32    []
    1.33 @@ -172,8 +149,8 @@
    1.34          creature (doto 
    1.35                       (load-blender-model thing)
    1.36                     (body!))
    1.37 -        touch-nerves (touch! creature)
    1.38 -        touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves)
    1.39 +        touch (touch! creature)
    1.40 +        touch-view (view-touch)
    1.41          vision-data (vision! creature)
    1.42          vision-debug (map (fn [_] (debug-vision-window)) vision-data)
    1.43          me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
    1.44 @@ -245,9 +222,7 @@
    1.45            
    1.46            (prop-debug (prop))
    1.47            
    1.48 -          (dorun
    1.49 -           (map #(%1 (%2 (.getRootNode world)))
    1.50 -                touch-debug-windows touch-nerves))
    1.51 +          (touch-view (map #(% (.getRootNode world)) touch))
    1.52            
    1.53            (dorun
    1.54             (map #(%1 (%2 world))
     2.1 --- a/org/touch.org	Sat Feb 04 09:11:42 2012 -0700
     2.2 +++ b/org/touch.org	Sat Feb 04 09:33:13 2012 -0700
     2.3 @@ -300,6 +300,35 @@
     2.4          (filter #(isa? (class %) Geometry)
     2.5                  (node-seq creature)))))
     2.6  
     2.7 +(defn gray-scale
     2.8 +  "Create a gray RGB pixel with R, G, and B set to 'num"
     2.9 +  [num]
    2.10 +  (+ num
    2.11 +     (bit-shift-left num 8)
    2.12 +     (bit-shift-left num 16)))
    2.13 +
    2.14 +(defn view-touch 
    2.15 +  "Creates a function which accepts touch sensor-data and displays it
    2.16 +   as BufferedImages in JFrames."
    2.17 +  []
    2.18 +  (let
    2.19 +      [windows (atom [])
    2.20 +       display-single-touch
    2.21 +       (fn 
    2.22 +         [[coords sensor-data] display]
    2.23 +         (let [image (points->image coords)]
    2.24 +           (dorun
    2.25 +            (for [i (range (count coords))]
    2.26 +              (.setRGB image ((coords i) 0) ((coords i) 1)
    2.27 +                       (gray-scale (sensor-data i)))))
    2.28 +           (display image)))]
    2.29 +    (fn [data]
    2.30 +      (if (> (count data) (count @windows))
    2.31 +        (reset! windows (map (fn [_] (view-image))
    2.32 +                             (range (count data)))))
    2.33 +      (dorun (map display-single-touch data @windows)))))
    2.34 +        
    2.35 +
    2.36  
    2.37  #+end_src
    2.38