Mercurial > vba-clojure
changeset 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 |
files | clojure/com/aurellem/run/image.clj gb-color-map.png |
diffstat | 2 files changed, 80 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/image.clj Mon Jun 11 10:07:01 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/image.clj Tue Jun 12 03:36:47 2012 -0500 1.3 @@ -192,5 +192,83 @@ 1.4 "," ",\n")] 1.5 (println out-str)))) 1.6 1.7 -(defn-memo gb-color-map [] 1.8 - (read-string (slurp gb-color-map-file))) 1.9 \ No newline at end of file 1.10 +(def gb-color-map 1.11 + (read-string (slurp gb-color-map-file))) 1.12 + 1.13 +(import javax.imageio.stream.FileImageOutputStream) 1.14 +(import '(javax.imageio ImageWriteParam IIOImage ImageIO)) 1.15 + 1.16 + 1.17 +(defn gen-gb-color-image! [] 1.18 + (let [im (BufferedImage. 181 182 BufferedImage/TYPE_INT_RGB) 1.19 + pix (vec 1.20 + 1.21 + (reduce 1.22 + concat 1.23 + (map (partial 1.24 + sort-by 1.25 + (fn [[r g b]] 1.26 + (let [s (max r g b) 1.27 + det 1.28 + (cond 1.29 + (= s r) 1.30 + (+ -1000 (- g) b) 1.31 + (= s b) 1.32 + (+ (- r) g) 1.33 + (= s g) 1.34 + (+ 1000 (- b) r))] 1.35 + det))) 1.36 + (partition 1.37 + 181 181 [] 1.38 + (sort-by 1.39 + (fn euclidean-distance [[r g b]] 1.40 + (Math/sqrt (+ (* r r) (* g g) (* b b)))) 1.41 + (vals gb-color-map)))))) 1.42 + view (cortex.sense/view-image) 1.43 + target (File. user-home "proj/vba-clojure/gb-color-map.png")] 1.44 + (dorun (for [x (range 181) y (range 182)] 1.45 + (let [[r g b] (get pix (+ x (* 181 y)) [0 0 0]) 1.46 + rgb (+ (bit-shift-left r 16) 1.47 + (bit-shift-left g 8) 1.48 + b)] 1.49 + (.setRGB im x y rgb)))) 1.50 + (view im) 1.51 + (doto 1.52 + (.next (ImageIO/getImageWritersByFormatName "png")) 1.53 + (.setOutput (FileImageOutputStream. target)) 1.54 + (.write (IIOImage. im nil nil)) 1.55 + (.dispose)) 1.56 + im)) 1.57 + 1.58 +(defn gen-gb-color-image*! [] 1.59 + (let [im (BufferedImage. 213 213 BufferedImage/TYPE_INT_RGB) 1.60 + squares 1.61 + (vec 1.62 + (for [r (range 32)] 1.63 + (vec 1.64 + (for [b (range 32) g (range 32)] 1.65 + (gb-color-map [r g b]))))) 1.66 + view (cortex.sense/view-image) 1.67 + target (File. user-home "proj/vba-clojure/gb-color-map.png")] 1.68 + 1.69 + (dorun 1.70 + (for [s-index (range 32)] 1.71 + (dorun 1.72 + (for [x (range 32) y (range 32)] 1.73 + 1.74 + (let [[r g b] ((squares s-index) (+ x (* 32 y))) 1.75 + rgb (+ (bit-shift-left r 16) 1.76 + (bit-shift-left g 8) 1.77 + b)] 1.78 + (.setRGB im 1.79 + (+ 3 (* 35 (rem s-index 6)) x) 1.80 + (+ 3 (* 35 (int (/ s-index 6))) y) 1.81 + rgb)))))) 1.82 + (view im) 1.83 + (doto 1.84 + (.next (ImageIO/getImageWritersByFormatName "png")) 1.85 + (.setOutput (FileImageOutputStream. target)) 1.86 + (.write (IIOImage. im nil nil)) 1.87 + (.dispose)) 1.88 + im)) 1.89 + 1.90 \ No newline at end of file
2.1 Binary file gb-color-map.png has changed