# HG changeset patch # User Robert McIntyre # Date 1328373739 25200 # Node ID 6142e85f58252f777cac90a86d3abb59c552bf82 # Parent 21816b27d7c81b7a6008c3b9446ad28961bb69d3 extracted common elements of display code diff -r 21816b27d7c8 -r 6142e85f5825 org/sense.org --- a/org/sense.org Sat Feb 04 09:35:15 2012 -0700 +++ b/org/sense.org Sat Feb 04 09:42:19 2012 -0700 @@ -214,6 +214,27 @@ (Vector3f. (.getX in) (.getZ in) (- (.getY in)))) + + +(defn view-sense + "Take a function that produces a BufferedImage from some sense data + and return a function which takes a list of sense and displays + those images in multiple JFrames." + [sense-display-kernel] + (let + [windows (atom [])] + (fn [data] + (if (> (count data) (count @windows)) + (reset! windows (map (fn [_] (view-image)) + (range (count data))))) + (dorun + (map + (fn [display gen data] + (display (gen data))) + @windows sense-display-kernel data))))) + + + #+end_src diff -r 21816b27d7c8 -r 6142e85f5825 org/touch.org --- a/org/touch.org Sat Feb 04 09:35:15 2012 -0700 +++ b/org/touch.org Sat Feb 04 09:42:19 2012 -0700 @@ -300,35 +300,27 @@ (filter #(isa? (class %) Geometry) (node-seq creature))))) -(defn gray-scale +(defn gray "Create a gray RGB pixel with R, G, and B set to 'num" [num] (+ num (bit-shift-left num 8) (bit-shift-left num 16))) -(defn view-touch +(defvar + view-touch + (view-sense + (fn + [[coords sensor-data]] + (let [image (points->image coords)] + (dorun + (for [i (range (count coords))] + (.setRGB image ((coords i) 0) ((coords i) 1) + (gray (sensor-data i))))) + image))) "Creates a function which accepts touch sensor-data and displays it - as BufferedImages in JFrames." - [] - (let - [windows (atom []) - display-single-touch - (fn - [[coords sensor-data] display] - (let [image (points->image coords)] - (dorun - (for [i (range (count coords))] - (.setRGB image ((coords i) 0) ((coords i) 1) - (gray-scale (sensor-data i))))) - (display image)))] - (fn [data] - (if (> (count data) (count @windows)) - (reset! windows (map (fn [_] (view-image)) - (range (count data))))) - (dorun (map display-single-touch data @windows))))) - - + as BufferedImages in JFrames.") + #+end_src