changeset 187:6142e85f5825

extracted common elements of display code
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 09:42:19 -0700
parents 21816b27d7c8
children 22548d48cc85
files org/sense.org org/touch.org
diffstat 2 files changed, 35 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/sense.org	Sat Feb 04 09:35:15 2012 -0700
     1.2 +++ b/org/sense.org	Sat Feb 04 09:42:19 2012 -0700
     1.3 @@ -214,6 +214,27 @@
     1.4    (Vector3f. (.getX in)
     1.5               (.getZ in)
     1.6               (- (.getY in))))
     1.7 +
     1.8 +
     1.9 +(defn view-sense 
    1.10 +  "Take a function that produces a BufferedImage from some sense data
    1.11 +   and return a function which takes a list of sense and displays
    1.12 +   those images in multiple JFrames."
    1.13 +  [sense-display-kernel]
    1.14 +  (let
    1.15 +      [windows (atom [])]
    1.16 +    (fn [data]
    1.17 +      (if (> (count data) (count @windows))
    1.18 +        (reset! windows (map (fn [_] (view-image))
    1.19 +                             (range (count data)))))
    1.20 +      (dorun
    1.21 +       (map
    1.22 +        (fn [display gen data]
    1.23 +          (display (gen data)))
    1.24 +        @windows sense-display-kernel data)))))
    1.25 +
    1.26 +  
    1.27 +
    1.28  #+end_src
    1.29  
    1.30  
     2.1 --- a/org/touch.org	Sat Feb 04 09:35:15 2012 -0700
     2.2 +++ b/org/touch.org	Sat Feb 04 09:42:19 2012 -0700
     2.3 @@ -300,35 +300,27 @@
     2.4          (filter #(isa? (class %) Geometry)
     2.5                  (node-seq creature)))))
     2.6  
     2.7 -(defn gray-scale
     2.8 +(defn gray
     2.9    "Create a gray RGB pixel with R, G, and B set to 'num"
    2.10    [num]
    2.11    (+ num
    2.12       (bit-shift-left num 8)
    2.13       (bit-shift-left num 16)))
    2.14  
    2.15 -(defn view-touch 
    2.16 +(defvar
    2.17 +  view-touch 
    2.18 +  (view-sense
    2.19 +   (fn 
    2.20 +     [[coords sensor-data]]
    2.21 +     (let [image (points->image coords)]
    2.22 +       (dorun
    2.23 +        (for [i (range (count coords))]
    2.24 +          (.setRGB image ((coords i) 0) ((coords i) 1)
    2.25 +                   (gray (sensor-data i)))))
    2.26 +       image)))
    2.27    "Creates a function which accepts touch sensor-data and displays it
    2.28 -   as BufferedImages in JFrames."
    2.29 -  []
    2.30 -  (let
    2.31 -      [windows (atom [])
    2.32 -       display-single-touch
    2.33 -       (fn 
    2.34 -         [[coords sensor-data] display]
    2.35 -         (let [image (points->image coords)]
    2.36 -           (dorun
    2.37 -            (for [i (range (count coords))]
    2.38 -              (.setRGB image ((coords i) 0) ((coords i) 1)
    2.39 -                       (gray-scale (sensor-data i)))))
    2.40 -           (display image)))]
    2.41 -    (fn [data]
    2.42 -      (if (> (count data) (count @windows))
    2.43 -        (reset! windows (map (fn [_] (view-image))
    2.44 -                             (range (count data)))))
    2.45 -      (dorun (map display-single-touch data @windows)))))
    2.46 -        
    2.47 -
    2.48 +   as BufferedImages in JFrames.")
    2.49 + 
    2.50  
    2.51  #+end_src
    2.52