Mercurial > cortex
comparison org/test-creature.org @ 101:65332841b7d9
topological sensor bundling appears to work
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 14 Jan 2012 04:28:37 -0700 |
parents | 940074adc1d5 |
children | 7eeb940bcbc8 |
comparison
equal
deleted
inserted
replaced
100:940074adc1d5 | 101:65332841b7d9 |
---|---|
96 | 96 |
97 (defn points->image | 97 (defn points->image |
98 "Take a sparse collection of points and visuliaze it as a | 98 "Take a sparse collection of points and visuliaze it as a |
99 BufferedImage." | 99 BufferedImage." |
100 [points] | 100 [points] |
101 (let [xs (map first points) | 101 (let [xs (vec (map first points)) |
102 ys (map second points) | 102 ys (vec (map second points)) |
103 width (- (apply max xs) (apply min xs)) | 103 x0 (apply min xs) |
104 height (- (apply max ys) (apply min ys)) | 104 y0 (apply min ys) |
105 image (BufferedImage. width height | 105 width (- (apply max xs) x0) |
106 BufferedImage/TYPE_BYTE_BINARY) | 106 height (- (apply max ys) y0) |
107 | 107 image (BufferedImage. (inc width) (inc height) |
108 | 108 BufferedImage/TYPE_BYTE_BINARY)] |
109 | 109 (dorun |
110 )) | 110 (for [index (range (count points))] |
111 (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) | |
112 | |
113 image)) | |
111 | 114 |
112 | 115 |
113 | 116 |
114 | 117 |
115 ;;(defn visualize [points] | 118 ;;(defn visualize [points] |
116 | 119 |
117 | 120 (defn test-data |
121 [] | |
122 (vec | |
123 (for [a (range 0 100 2) | |
124 b (range 0 100 2)] | |
125 (vector a b)) | |
126 )) | |
127 | |
128 (defn average [coll] | |
129 (/ (reduce + coll) (count coll))) | |
130 | |
131 (defn collapse-1d | |
132 "One dimensional analogue of collapse" | |
133 [center line] | |
134 (let [length (count line) | |
135 num-above (count (filter (partial < center) line)) | |
136 num-below (- length num-above)] | |
137 (range (- center num-below) | |
138 (+ center num-above)) | |
139 )) | |
118 | 140 |
119 (defn collapse | 141 (defn collapse |
120 "Take a set of pairs of integers and collapse them into a | 142 "Take a set of pairs of integers and collapse them into a |
121 contigous bitmap." | 143 contigous bitmap." |
122 [points] | 144 [points] |
123 (let [center [0 0]] | 145 (let |
124 | 146 [num-points (count points) |
125 ) | 147 center (vector |
126 | 148 (average (map first points)) |
127 | 149 (average (map first points))) |
128 | 150 flattened |
129 | 151 (reduce |
130 | 152 concat |
131 | 153 (map |
132 | 154 (fn [column] |
133 | 155 (map vector |
156 (map first column) | |
157 (collapse-1d (second center) | |
158 (map second column)))) | |
159 (partition-by first (sort-by first points)))) | |
160 squeezed | |
161 (reduce | |
162 concat | |
163 (map | |
164 (fn [row] | |
165 (map vector | |
166 (collapse-1d (first center) | |
167 (map first row)) | |
168 (map second row))) | |
169 (partition-by second (sort-by second flattened))))] | |
170 squeezed | |
171 )) | |
172 | |
134 | 173 |
135 | 174 |
136 (defn load-bullet [] | 175 (defn load-bullet [] |
137 (let [sim (world (Node.) {} no-op no-op)] | 176 (let [sim (world (Node.) {} no-op no-op)] |
138 (.enqueue | 177 (.enqueue |