# HG changeset patch # User Robert McIntyre # Date 1329146425 25200 # Node ID e9bce4f722b171085ac7a6368e28a5dee6924fe2 # Parent 95a9f6f1cb823afd5d2d6040eedfbd9f21a4b2fb added basic touch video... going to bed... diff -r 95a9f6f1cb82 -r e9bce4f722b1 org/touch.org --- a/org/touch.org Mon Feb 13 06:06:02 2012 -0700 +++ b/org/touch.org Mon Feb 13 08:20:25 2012 -0700 @@ -483,19 +483,15 @@ (let [image (points->image coords)] (dorun (for [i (range (count coords))] - (do - (if (= i 500) (println-repl (sensor-data i))) - - (comment - (.setRGB image ((coords i) 0) ((coords i) 1) - (apply touch->gray (sensor-data i))))))) + (.setRGB image ((coords i) 0) ((coords i) 1) + (apply touch->gray (sensor-data i))))) image)))) #+end_src #+results: visualization : #'cortex.touch/view-touch -* COMMENT Basic Test of Touch +* Basic Test of Touch The worm's sense of touch is a bit complicated, so for this basic test I'll use a new creature --- a simple cube which has touch sensors @@ -534,29 +530,92 @@ #+begin_src clojure (in-ns 'cortex.test.touch) +(import com.aurellem.capture.Capture) +(import java.io.File) + (defn test-basic-touch ([] (test-basic-touch false)) ([record?] (let [the-cube (doto (touch-cube) (body!)) touch (touch! the-cube) touch-display (view-touch)] - (world (nodify [the-cube - (box 10 1 10 :position (Vector3f. 0 -10 0) - :color ColorRGBA/Gray :mass 0)]) + (world + (nodify [the-cube + (box 10 1 10 :position (Vector3f. 0 -10 0) + :color ColorRGBA/Gray :mass 0)]) + + standard-debug-controls + + (fn [world] + (if record? + (Capture/captureVideo + world + (File. "/home/r/proj/cortex/render/touch-cube/main-view/"))) + (speed-up world) + (light-up-everything world)) + + (fn [world tpf] + (touch-display + (map #(% (.getRootNode world)) touch) + (if record? + (File. "/home/r/proj/cortex/render/touch-cube/touch/")))))))) +#+end_src - standard-debug-controls - - (fn [world] - (speed-up world) - (light-up-everything world)) +** Basic Touch Demonstration - (fn [world tpf] - (touch-display - (map #(% (.getRootNode world)) touch))))))) - +#+begin_html +
+
+ +
+

The simple creature responds to touch.

+
+#+end_html +** Generating the Basic Touch Video +#+begin_src clojure +(ns cortex.video.magick4 + (:import java.io.File) + (:use clojure.contrib.shell-out)) + +(defn images [path] + (sort (rest (file-seq (File. path))))) + +(def base "/home/r/proj/cortex/render/touch-cube/") + +(defn pics [file] + (images (str base file))) + +(defn combine-images [] + (let [main-view (pics "main-view") + touch (pics "touch/0") + background (repeat 9001 (File. (str base "background.png"))) + targets (map + #(File. (str base "out/" (format "%07d.png" %))) + (range 0 (count main-view)))] + (dorun + (pmap + (comp + (fn [[background main-view touch target]] + (println target) + (sh "convert" + touch + "-resize" "x300" + "-rotate" "180" + background + "-swap" "0,1" + "-geometry" "+776+129" + "-composite" + main-view "-geometry" "+66+21" "-composite" + target)) + (fn [& args] (map #(.getCanonicalPath %) args))) + background main-view touch targets)))) #+end_src + * Adding Touch to the Worm #+name: test-touch