comparison 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
comparison
equal deleted inserted replaced
186:21816b27d7c8 187:6142e85f5825
298 (comp not nil?) 298 (comp not nil?)
299 (map touch-fn 299 (map touch-fn
300 (filter #(isa? (class %) Geometry) 300 (filter #(isa? (class %) Geometry)
301 (node-seq creature))))) 301 (node-seq creature)))))
302 302
303 (defn gray-scale 303 (defn gray
304 "Create a gray RGB pixel with R, G, and B set to 'num" 304 "Create a gray RGB pixel with R, G, and B set to 'num"
305 [num] 305 [num]
306 (+ num 306 (+ num
307 (bit-shift-left num 8) 307 (bit-shift-left num 8)
308 (bit-shift-left num 16))) 308 (bit-shift-left num 16)))
309 309
310 (defn view-touch 310 (defvar
311 view-touch
312 (view-sense
313 (fn
314 [[coords sensor-data]]
315 (let [image (points->image coords)]
316 (dorun
317 (for [i (range (count coords))]
318 (.setRGB image ((coords i) 0) ((coords i) 1)
319 (gray (sensor-data i)))))
320 image)))
311 "Creates a function which accepts touch sensor-data and displays it 321 "Creates a function which accepts touch sensor-data and displays it
312 as BufferedImages in JFrames." 322 as BufferedImages in JFrames.")
313 [] 323
314 (let
315 [windows (atom [])
316 display-single-touch
317 (fn
318 [[coords sensor-data] display]
319 (let [image (points->image coords)]
320 (dorun
321 (for [i (range (count coords))]
322 (.setRGB image ((coords i) 0) ((coords i) 1)
323 (gray-scale (sensor-data i)))))
324 (display image)))]
325 (fn [data]
326 (if (> (count data) (count @windows))
327 (reset! windows (map (fn [_] (view-image))
328 (range (count data)))))
329 (dorun (map display-single-touch data @windows)))))
330
331
332 324
333 #+end_src 325 #+end_src
334 326
335 327
336 * Example 328 * Example