comparison org/touch.org @ 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 11bd5f0625ad
children 6142e85f5825
comparison
equal deleted inserted replaced
184:bdca0daa3778 185:cfb71209ddc6
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
304 "Create a gray RGB pixel with R, G, and B set to 'num"
305 [num]
306 (+ num
307 (bit-shift-left num 8)
308 (bit-shift-left num 16)))
309
310 (defn view-touch
311 "Creates a function which accepts touch sensor-data and displays it
312 as BufferedImages in JFrames."
313 []
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
303 332
304 #+end_src 333 #+end_src
305 334
306 335
307 * Example 336 * Example