comparison org/test-creature.org @ 119:ebfd62779ab4

color selection enabled
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Jan 2012 08:30:28 -0700
parents 1261444da2c7
children 83e638955e89
comparison
equal deleted inserted replaced
118:1261444da2c7 119:ebfd62779ab4
81 x0 (apply min xs) 81 x0 (apply min xs)
82 y0 (apply min ys) 82 y0 (apply min ys)
83 width (- (apply max xs) x0) 83 width (- (apply max xs) x0)
84 height (- (apply max ys) y0) 84 height (- (apply max ys) y0)
85 image (BufferedImage. (inc width) (inc height) 85 image (BufferedImage. (inc width) (inc height)
86 BufferedImage/TYPE_4BYTE_ABGR)] 86 BufferedImage/TYPE_INT_RGB)]
87 (dorun 87 (dorun
88 (for [x (range (.getWidth image)) 88 (for [x (range (.getWidth image))
89 y (range (.getHeight image))] 89 y (range (.getHeight image))]
90 (.setRGB image x y 0xFFFF0000))) 90 (.setRGB image x y 0xFF0000)))
91 (dorun 91 (dorun
92 (for [index (range (count points))] 92 (for [index (range (count points))]
93 (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) 93 (.setRGB image (- (xs index) x0) (- (ys index) y0) -1)))
94 94
95 image))) 95 image)))
747 (let [target (eye-target creature eye) 747 (let [target (eye-target creature eye)
748 [cam-width cam-height] (eye-dimensions eye) 748 [cam-width cam-height] (eye-dimensions eye)
749 cam (Camera. cam-width cam-height)] 749 cam (Camera. cam-width cam-height)]
750 (.setLocation cam (.getWorldTranslation eye)) 750 (.setLocation cam (.getWorldTranslation eye))
751 (.setRotation cam (.getWorldRotation eye)) 751 (.setRotation cam (.getWorldRotation eye))
752 (.setFrustumPerspective
753 cam 45 (/ (.getWidth cam) (.getHeight cam))
754 1 1000)
755
752 (bind-camera target cam) 756 (bind-camera target cam)
753 cam)) 757 cam))
754 758
755 759
756 (def presets 760 (def presets
757 {:gray identity}) 761 {:all 0x000000
762 :red 0xFF0000
763 :blue 0x0000FF
764 :green 0x00FF00})
765
766
758 767
759 (defn enable-vision 768 (defn enable-vision
760 "return [init-function sensor-functions] for a particular eye" 769 "return [init-function sensor-functions] for a particular eye"
761 [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}] 770 [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}]
762 (let [retinal-map (retina-sensor-image eye) 771 (let [retinal-map (retina-sensor-image eye)
768 world camera 777 world camera
769 (let [counter (atom 0)] 778 (let [counter (atom 0)]
770 (fn [r fb bb bi] 779 (fn [r fb bb bi]
771 (if (zero? (rem (swap! counter inc) (inc skip))) 780 (if (zero? (rem (swap! counter inc) (inc skip)))
772 (reset! vision-image (BufferedImage! r fb bb bi))))))) 781 (reset! vision-image (BufferedImage! r fb bb bi)))))))
773 (vector 782 (vec
774 (let [whites (white-coordinates (:gray retinal-map)) 783 (map
775 topology (vec (collapse whites))] 784 (fn [[key image]]
776 (fn [] 785 (let [whites (white-coordinates image)
777 (vector 786 topology (vec (collapse whites))
778 topology 787 mask (presets key)]
779 (vec 788 (fn []
780 (for [[x y] whites] 789 (vector
781 (.getRGB @vision-image x y))))))) 790 topology
791 (vec
792 (for [[x y] whites]
793 (bit-xor
794 mask (.getRGB @vision-image x y))))))))
795 retinal-map))
782 ])) 796 ]))
783 797
784 (defn vision 798 (defn vision
785 799
786 ;; need to create a camera based on UV image, 800 ;; need to create a camera based on UV image,
880 (add-eye world (.getCamera world) no-op) 894 (add-eye world (.getCamera world) no-op)
881 895
882 ;;(com.aurellem.capture.Capture/captureVideo 896 ;;(com.aurellem.capture.Capture/captureVideo
883 ;; world (file-str "/home/r/proj/ai-videos/hand")) 897 ;; world (file-str "/home/r/proj/ai-videos/hand"))
884 ;;(.setTimer world (RatchetTimer. 60)) 898 ;;(.setTimer world (RatchetTimer. 60))
885 ;;(speed-up world) 899 (speed-up world)
886 ;;(set-gravity world (Vector3f. 0 0 0)) 900 ;;(set-gravity world (Vector3f. 0 0 0))
887 ) 901 )
888 (fn [world tpf] 902 (fn [world tpf]
889 ;;(dorun 903 ;;(dorun
890 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) 904 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world))))