Mercurial > vba-clojure
comparison clojure/com/aurellem/run/image.clj @ 499:8b8053ccb33c
generated graphical representation of the gb color map.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 12 Jun 2012 03:36:47 -0500 |
parents | 554883a95de0 |
children | 0273c08cd2ff |
comparison
equal
deleted
inserted
replaced
498:554883a95de0 | 499:8b8053ccb33c |
---|---|
190 (str | 190 (str |
191 (into (sorted-map) (generate-gb-color-map))) | 191 (into (sorted-map) (generate-gb-color-map))) |
192 "," ",\n")] | 192 "," ",\n")] |
193 (println out-str)))) | 193 (println out-str)))) |
194 | 194 |
195 (defn-memo gb-color-map [] | 195 (def gb-color-map |
196 (read-string (slurp gb-color-map-file))) | 196 (read-string (slurp gb-color-map-file))) |
197 | |
198 (import javax.imageio.stream.FileImageOutputStream) | |
199 (import '(javax.imageio ImageWriteParam IIOImage ImageIO)) | |
200 | |
201 | |
202 (defn gen-gb-color-image! [] | |
203 (let [im (BufferedImage. 181 182 BufferedImage/TYPE_INT_RGB) | |
204 pix (vec | |
205 | |
206 (reduce | |
207 concat | |
208 (map (partial | |
209 sort-by | |
210 (fn [[r g b]] | |
211 (let [s (max r g b) | |
212 det | |
213 (cond | |
214 (= s r) | |
215 (+ -1000 (- g) b) | |
216 (= s b) | |
217 (+ (- r) g) | |
218 (= s g) | |
219 (+ 1000 (- b) r))] | |
220 det))) | |
221 (partition | |
222 181 181 [] | |
223 (sort-by | |
224 (fn euclidean-distance [[r g b]] | |
225 (Math/sqrt (+ (* r r) (* g g) (* b b)))) | |
226 (vals gb-color-map)))))) | |
227 view (cortex.sense/view-image) | |
228 target (File. user-home "proj/vba-clojure/gb-color-map.png")] | |
229 (dorun (for [x (range 181) y (range 182)] | |
230 (let [[r g b] (get pix (+ x (* 181 y)) [0 0 0]) | |
231 rgb (+ (bit-shift-left r 16) | |
232 (bit-shift-left g 8) | |
233 b)] | |
234 (.setRGB im x y rgb)))) | |
235 (view im) | |
236 (doto | |
237 (.next (ImageIO/getImageWritersByFormatName "png")) | |
238 (.setOutput (FileImageOutputStream. target)) | |
239 (.write (IIOImage. im nil nil)) | |
240 (.dispose)) | |
241 im)) | |
242 | |
243 (defn gen-gb-color-image*! [] | |
244 (let [im (BufferedImage. 213 213 BufferedImage/TYPE_INT_RGB) | |
245 squares | |
246 (vec | |
247 (for [r (range 32)] | |
248 (vec | |
249 (for [b (range 32) g (range 32)] | |
250 (gb-color-map [r g b]))))) | |
251 view (cortex.sense/view-image) | |
252 target (File. user-home "proj/vba-clojure/gb-color-map.png")] | |
253 | |
254 (dorun | |
255 (for [s-index (range 32)] | |
256 (dorun | |
257 (for [x (range 32) y (range 32)] | |
258 | |
259 (let [[r g b] ((squares s-index) (+ x (* 32 y))) | |
260 rgb (+ (bit-shift-left r 16) | |
261 (bit-shift-left g 8) | |
262 b)] | |
263 (.setRGB im | |
264 (+ 3 (* 35 (rem s-index 6)) x) | |
265 (+ 3 (* 35 (int (/ s-index 6))) y) | |
266 rgb)))))) | |
267 (view im) | |
268 (doto | |
269 (.next (ImageIO/getImageWritersByFormatName "png")) | |
270 (.setOutput (FileImageOutputStream. target)) | |
271 (.write (IIOImage. im nil nil)) | |
272 (.dispose)) | |
273 im)) | |
274 |