diff org/test-creature.org @ 92:e70ec4bba96b

saving progress...
author Robert McIntyre <rlm@mit.edu>
date Mon, 09 Jan 2012 06:05:29 -0700
parents 2bcc7636cfea
children 7b739503836a
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Mon Jan 09 06:02:06 2012 -0700
     1.2 +++ b/org/test-creature.org	Mon Jan 09 06:05:29 2012 -0700
     1.3 @@ -378,15 +378,11 @@
     1.4    (frame [image+]
     1.5      (frame (.getBufferedImage image+))))
     1.6  
     1.7 -(defn rgb->int [r g b]
     1.8 -  (+ (bit-shift-left r 16)
     1.9 -     (bit-shift-left g 8)
    1.10 -     b))
    1.11 -     
    1.12 -  
    1.13 +(def white -1)
    1.14  
    1.15  (defn filter-pixels
    1.16    "List the coordinates of all pixels matching pred."
    1.17 +  {:author "Dylan Holmes"}
    1.18    [pred #^ImageProcessor ip]
    1.19    (let
    1.20        [width (.getWidth ip)
    1.21 @@ -400,109 +396,11 @@
    1.22          :else (recur (inc x) y matches)))
    1.23       0 0 [])))
    1.24  
    1.25 -
    1.26 -
    1.27 -
    1.28 -
    1.29 -(defn filter-pixels*
    1.30 -  [pred #^ImageProcessor ip]
    1.31 -  (let
    1.32 -      [width (.getWidth ip)
    1.33 -       height (.getHeight ip)
    1.34 -       coords (ref [])
    1.35 -       process 
    1.36 -       (fn [[start end]]
    1.37 -         (loop [i start]
    1.38 -           (if (<= i end)
    1.39 -             (do 
    1.40 -               (let [column (rem i height)
    1.41 -                     row (unchecked-divide i width)]
    1.42 -                 (if (pred (.getPixel ip row column))
    1.43 -                   (dosync (ref-set
    1.44 -                            coords
    1.45 -                            (conj @coords (Vector2f. column row)))))
    1.46 -        
    1.47 -               (recur (inc i)))))))
    1.48 -       ]
    1.49 -
    1.50 -       
    1.51 -    (dorun 
    1.52 -     (pmap process (partition
    1.53 -                    2
    1.54 -                    (conj (vec (range 0 (* width height) 100))
    1.55 -                          (* width height)))))
    1.56 -    @coords))
    1.57 -
    1.58 -
    1.59 -
    1.60 -(comment
    1.61 -  ((->
    1.62 -    f
    1.63 -    (partial x)
    1.64 -    (partial y)
    1.65 -    (partial z))))
    1.66 -
    1.67 -(defn filter-pixels**
    1.68 -  [pred #^ImageProcessor ip]
    1.69 -  (let [width (.getWidth ip)
    1.70 -        height (.getHeight ip)]
    1.71 -    ((fn f [x1 x2 y1 y2]
    1.72 -       (println x1)
    1.73 -         (if
    1.74 -             (and
    1.75 -              (= x1 (dec x2))
    1.76 -              (= y1 (dec y2)))
    1.77 -           (if (pred (.getPixel ip x1 y1))
    1.78 -             [[x1 y1]]
    1.79 -             [])
    1.80 -           (let
    1.81 -               [xm (+ x1 (/ (- x2 x1) 2))
    1.82 -                ym (+ y1 (/ (- y2 y1) 2))]
    1.83 -           (apply concat
    1.84 -           (pvalues
    1.85 -            ;;(f x1 xm y1 ym)
    1.86 -            ;;(f xm x2 y1 ym)
    1.87 -            ;;(f x1 xm ym y2)
    1.88 -            (f xm x2 ym y2))))))
    1.89 -       0 width 0 height)))
    1.90 -    
    1.91 -
    1.92 -
    1.93 -
    1.94 -  
    1.95 -       
    1.96 -
    1.97 -
    1.98 -(defn white-coordinates*
    1.99 -  [#^ImageProcessor ip]
   1.100 -  (filter-pixels** #(== % -1) ip))
   1.101 -  
   1.102 -
   1.103  (defn white-coordinates
   1.104    "List the coordinates of all the white pixels in an image."
   1.105    [#^ImageProcessor ip]
   1.106 -  (let [height (.getHeight ip)
   1.107 -        width  (.getWidth  ip)
   1.108 -        coords (transient [])]
   1.109 -    (dorun 
   1.110 -     (for [x (range width)
   1.111 -           y (range height)]
   1.112 -       (let [pixel (.getPixel ip x y)]
   1.113 -         (if (= pixel -1)
   1.114 -           (conj! coords (Vector2f. x y))))))
   1.115 -    (persistent! coords)))
   1.116 -                                    
   1.117 -        
   1.118 -
   1.119 -
   1.120 -
   1.121 -    
   1.122 +  (filter-pixels #(= % white) ip))
   1.123    
   1.124 -
   1.125 -(def white {:r 255, :g 255, :b 255})
   1.126 -(def black {:r 0,   :g 0,   :b 0})
   1.127 -
   1.128 -
   1.129  (defn same-side? [p1 p2 ref p]
   1.130    (<=
   1.131     0