comparison org/touch.org @ 250:e9bce4f722b1

added basic touch video... going to bed...
author Robert McIntyre <rlm@mit.edu>
date Mon, 13 Feb 2012 08:20:25 -0700
parents 95a9f6f1cb82
children f1a74d23e7e4
comparison
equal deleted inserted replaced
249:95a9f6f1cb82 250:e9bce4f722b1
481 (view-sense 481 (view-sense
482 (fn [[coords sensor-data]] 482 (fn [[coords sensor-data]]
483 (let [image (points->image coords)] 483 (let [image (points->image coords)]
484 (dorun 484 (dorun
485 (for [i (range (count coords))] 485 (for [i (range (count coords))]
486 (do 486 (.setRGB image ((coords i) 0) ((coords i) 1)
487 (if (= i 500) (println-repl (sensor-data i))) 487 (apply touch->gray (sensor-data i)))))
488
489 (comment
490 (.setRGB image ((coords i) 0) ((coords i) 1)
491 (apply touch->gray (sensor-data i)))))))
492 image)))) 488 image))))
493 #+end_src 489 #+end_src
494 490
495 #+results: visualization 491 #+results: visualization
496 : #'cortex.touch/view-touch 492 : #'cortex.touch/view-touch
497 493
498 * COMMENT Basic Test of Touch 494 * Basic Test of Touch
499 495
500 The worm's sense of touch is a bit complicated, so for this basic test 496 The worm's sense of touch is a bit complicated, so for this basic test
501 I'll use a new creature --- a simple cube which has touch sensors 497 I'll use a new creature --- a simple cube which has touch sensors
502 evenly distributed along each of its sides. 498 evenly distributed along each of its sides.
503 499
532 [[../images/touch-profile.png]] 528 [[../images/touch-profile.png]]
533 529
534 #+begin_src clojure 530 #+begin_src clojure
535 (in-ns 'cortex.test.touch) 531 (in-ns 'cortex.test.touch)
536 532
533 (import com.aurellem.capture.Capture)
534 (import java.io.File)
535
537 (defn test-basic-touch 536 (defn test-basic-touch
538 ([] (test-basic-touch false)) 537 ([] (test-basic-touch false))
539 ([record?] 538 ([record?]
540 (let [the-cube (doto (touch-cube) (body!)) 539 (let [the-cube (doto (touch-cube) (body!))
541 touch (touch! the-cube) 540 touch (touch! the-cube)
542 touch-display (view-touch)] 541 touch-display (view-touch)]
543 (world (nodify [the-cube 542 (world
544 (box 10 1 10 :position (Vector3f. 0 -10 0) 543 (nodify [the-cube
545 :color ColorRGBA/Gray :mass 0)]) 544 (box 10 1 10 :position (Vector3f. 0 -10 0)
546 545 :color ColorRGBA/Gray :mass 0)])
547 standard-debug-controls 546
548 547 standard-debug-controls
549 (fn [world] 548
550 (speed-up world) 549 (fn [world]
551 (light-up-everything world)) 550 (if record?
552 551 (Capture/captureVideo
553 (fn [world tpf] 552 world
554 (touch-display 553 (File. "/home/r/proj/cortex/render/touch-cube/main-view/")))
555 (map #(% (.getRootNode world)) touch))))))) 554 (speed-up world)
556 555 (light-up-everything world))
557 556
558 #+end_src 557 (fn [world tpf]
558 (touch-display
559 (map #(% (.getRootNode world)) touch)
560 (if record?
561 (File. "/home/r/proj/cortex/render/touch-cube/touch/"))))))))
562 #+end_src
563
564 ** Basic Touch Demonstration
565
566 #+begin_html
567 <div class="figure">
568 <center>
569 <video controls="controls" width="755">
570 <source src="../video/basic-touch.ogg" type="video/ogg"
571 preload="none" poster="../images/aurellem-1280x480.png" />
572 </video>
573 </center>
574 <p>The simple creature responds to touch.</p>
575 </div>
576 #+end_html
577
578 ** Generating the Basic Touch Video
579 #+begin_src clojure
580 (ns cortex.video.magick4
581 (:import java.io.File)
582 (:use clojure.contrib.shell-out))
583
584 (defn images [path]
585 (sort (rest (file-seq (File. path)))))
586
587 (def base "/home/r/proj/cortex/render/touch-cube/")
588
589 (defn pics [file]
590 (images (str base file)))
591
592 (defn combine-images []
593 (let [main-view (pics "main-view")
594 touch (pics "touch/0")
595 background (repeat 9001 (File. (str base "background.png")))
596 targets (map
597 #(File. (str base "out/" (format "%07d.png" %)))
598 (range 0 (count main-view)))]
599 (dorun
600 (pmap
601 (comp
602 (fn [[background main-view touch target]]
603 (println target)
604 (sh "convert"
605 touch
606 "-resize" "x300"
607 "-rotate" "180"
608 background
609 "-swap" "0,1"
610 "-geometry" "+776+129"
611 "-composite"
612 main-view "-geometry" "+66+21" "-composite"
613 target))
614 (fn [& args] (map #(.getCanonicalPath %) args)))
615 background main-view touch targets))))
616 #+end_src
617
559 618
560 * Adding Touch to the Worm 619 * Adding Touch to the Worm
561 620
562 #+name: test-touch 621 #+name: test-touch
563 #+begin_src clojure 622 #+begin_src clojure