diff org/vision.org @ 170:1a00b4918529

removed vision-init-fns requirement; changed names
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 05:00:10 -0700
parents 94b79c191fc7
children 15bde60217aa
line wrap: on
line diff
     1.1 --- a/org/vision.org	Sat Feb 04 04:23:32 2012 -0700
     1.2 +++ b/org/vision.org	Sat Feb 04 05:00:10 2012 -0700
     1.3 @@ -7,7 +7,7 @@
     1.4  #+INCLUDE: ../../aurellem/org/level-0.org
     1.5  #+babel: :mkdirp yes :noweb yes :exports both
     1.6  
     1.7 -* Vision
     1.8 +* COMMENT Vision
     1.9  
    1.10  I want to make creatures with eyes. Each eye can be independely moved
    1.11  and should see its own version of the world depending on where it is.
    1.12 @@ -193,37 +193,43 @@
    1.13          (atom
    1.14           (BufferedImage. (.getWidth camera)
    1.15                           (.getHeight camera)
    1.16 -                         BufferedImage/TYPE_BYTE_BINARY))]
    1.17 -    [(fn [world]
    1.18 -       (add-camera!
    1.19 -        world camera
    1.20 -        (let [counter  (atom 0)]
    1.21 -          (fn [r fb bb bi]
    1.22 -            (if (zero? (rem (swap! counter inc) (inc skip)))
    1.23 -              (reset! vision-image (BufferedImage! r fb bb bi)))))))
    1.24 +                         BufferedImage/TYPE_BYTE_BINARY))
    1.25 +        register-eye!
    1.26 +        (runonce
    1.27 +         (fn [world]
    1.28 +           (add-camera!
    1.29 +            world camera
    1.30 +            (let [counter  (atom 0)]
    1.31 +              (fn [r fb bb bi]
    1.32 +                (if (zero? (rem (swap! counter inc) (inc skip)))
    1.33 +                  (reset! vision-image
    1.34 +                          (BufferedImage! r fb bb bi))))))))]
    1.35       (vec
    1.36        (map
    1.37         (fn [[key image]]
    1.38           (let [whites (white-coordinates image)
    1.39                 topology (vec (collapse whites))
    1.40                 mask (presets key)]
    1.41 -           (fn []
    1.42 +           (fn [world]
    1.43 +             (register-eye! world)
    1.44               (vector
    1.45                topology
    1.46                (vec 
    1.47                 (for [[x y] whites]
    1.48                   (bit-and
    1.49                    mask (.getRGB @vision-image x y))))))))
    1.50 -       retinal-map))]))
    1.51 +       retinal-map))))
    1.52  
    1.53 -(defn vision
    1.54 +
    1.55 +;; TODO maybe should add a viewport-manipulation function to
    1.56 +;; automatically change viewport settings, attach shadow filters, etc.
    1.57 +
    1.58 +(defn vision!
    1.59 +  "Returns a function which returns visual sensory data when called
    1.60 +   inside a running simulation"
    1.61    [#^Node creature & {skip :skip :or {skip 0}}]
    1.62    (reduce
    1.63 -   (fn [[init-a senses-a]
    1.64 -        [init-b senses-b]]
    1.65 -     [(conj init-a init-b)
    1.66 -      (into senses-a senses-b)])
    1.67 -   [[][]]      
    1.68 +   concat 
    1.69     (for [eye (eyes creature)]
    1.70       (vision-fn creature eye))))
    1.71