diff org/touch.org @ 187:6142e85f5825

extracted common elements of display code
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 09:42:19 -0700
parents cfb71209ddc6
children 22548d48cc85
line wrap: on
line diff
     1.1 --- a/org/touch.org	Sat Feb 04 09:35:15 2012 -0700
     1.2 +++ b/org/touch.org	Sat Feb 04 09:42:19 2012 -0700
     1.3 @@ -300,35 +300,27 @@
     1.4          (filter #(isa? (class %) Geometry)
     1.5                  (node-seq creature)))))
     1.6  
     1.7 -(defn gray-scale
     1.8 +(defn gray
     1.9    "Create a gray RGB pixel with R, G, and B set to 'num"
    1.10    [num]
    1.11    (+ num
    1.12       (bit-shift-left num 8)
    1.13       (bit-shift-left num 16)))
    1.14  
    1.15 -(defn view-touch 
    1.16 +(defvar
    1.17 +  view-touch 
    1.18 +  (view-sense
    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 (sensor-data i)))))
    1.26 +       image)))
    1.27    "Creates a function which accepts touch sensor-data and displays it
    1.28 -   as BufferedImages in JFrames."
    1.29 -  []
    1.30 -  (let
    1.31 -      [windows (atom [])
    1.32 -       display-single-touch
    1.33 -       (fn 
    1.34 -         [[coords sensor-data] display]
    1.35 -         (let [image (points->image coords)]
    1.36 -           (dorun
    1.37 -            (for [i (range (count coords))]
    1.38 -              (.setRGB image ((coords i) 0) ((coords i) 1)
    1.39 -                       (gray-scale (sensor-data i)))))
    1.40 -           (display image)))]
    1.41 -    (fn [data]
    1.42 -      (if (> (count data) (count @windows))
    1.43 -        (reset! windows (map (fn [_] (view-image))
    1.44 -                             (range (count data)))))
    1.45 -      (dorun (map display-single-touch data @windows)))))
    1.46 -        
    1.47 -
    1.48 +   as BufferedImages in JFrames.")
    1.49 + 
    1.50  
    1.51  #+end_src
    1.52