comparison clojure/com/aurellem/run/image.clj @ 500:0273c08cd2ff

discovered that the gb has far fewer unique colors than I initially thought.
author Robert McIntyre <rlm@mit.edu>
date Tue, 12 Jun 2012 08:05:24 -0500
parents 8b8053ccb33c
children 4c43b2b8d3c0
comparison
equal deleted inserted replaced
499:8b8053ccb33c 500:0273c08cd2ff
153 view (cortex.sense/view-image)] 153 view (cortex.sense/view-image)]
154 (dorun (for [x (range 160) y (range 144)] 154 (dorun (for [x (range 160) y (range 144)]
155 (.setRGB im x y (pix (+ x (* 160 y)))))) 155 (.setRGB im x y (pix (+ x (* 160 y))))))
156 (view im))) 156 (view im)))
157 157
158 (defn-memo gb-rgb->vga-rgb [[r g b]] 158 (defn gb-rgb->vga-rgb [[r g b]]
159 (let [vga-rgb 159 (let [vga-rgb
160 (first (pixels 160 (first (pixels
161 (run-moves 161 (run-moves
162 (display-one-color 162 (display-one-color
163 (tick @current-state) 163 (tick @current-state)
198 (import javax.imageio.stream.FileImageOutputStream) 198 (import javax.imageio.stream.FileImageOutputStream)
199 (import '(javax.imageio ImageWriteParam IIOImage ImageIO)) 199 (import '(javax.imageio ImageWriteParam IIOImage ImageIO))
200 200
201 201
202 (defn gen-gb-color-image! [] 202 (defn gen-gb-color-image! []
203 (let [im (BufferedImage. 181 182 BufferedImage/TYPE_INT_RGB) 203 (let [im (BufferedImage. 68 69 BufferedImage/TYPE_INT_RGB)
204 pix (vec 204 pix (vec
205 205
206 (reduce 206 (reduce
207 concat 207 concat
208 (map (partial 208 (map (partial
217 (+ (- r) g) 217 (+ (- r) g)
218 (= s g) 218 (= s g)
219 (+ 1000 (- b) r))] 219 (+ 1000 (- b) r))]
220 det))) 220 det)))
221 (partition 221 (partition
222 181 181 [] 222 68 68 []
223 (sort-by 223 (sort-by
224 (fn euclidean-distance [[r g b]] 224 (fn euclidean-distance [[r g b]]
225 (Math/sqrt (+ (* r r) (* g g) (* b b)))) 225 (Math/sqrt (+ (* r r) (* g g) (* b b))))
226 (vals gb-color-map)))))) 226 (seq (set (vals gb-color-map))))))))
227 view (cortex.sense/view-image) 227 view (cortex.sense/view-image)
228 target (File. user-home "proj/vba-clojure/gb-color-map.png")] 228 target (File. user-home "proj/vba-clojure/gb-color-map-unique.png")]
229 (dorun (for [x (range 181) y (range 182)] 229 (dorun (for [x (range 68) y (range 69)]
230 (let [[r g b] (get pix (+ x (* 181 y)) [0 0 0]) 230 (let [[r g b] (get pix (+ x (* 68 y)) [0 0 0])
231 rgb (+ (bit-shift-left r 16) 231 rgb (+ (bit-shift-left r 16)
232 (bit-shift-left g 8) 232 (bit-shift-left g 8)
233 b)] 233 b)]
234 (.setRGB im x y rgb)))) 234 (.setRGB im x y rgb))))
235 (view im) 235 (view im)
269 (.next (ImageIO/getImageWritersByFormatName "png")) 269 (.next (ImageIO/getImageWritersByFormatName "png"))
270 (.setOutput (FileImageOutputStream. target)) 270 (.setOutput (FileImageOutputStream. target))
271 (.write (IIOImage. im nil nil)) 271 (.write (IIOImage. im nil nil))
272 (.dispose)) 272 (.dispose))
273 im)) 273 im))
274 274