comparison src/laser/rasterize.clj @ 1:6d9bdaf919f7

added clojureDemo source
author Robert McIntyre <rlm@mit.edu>
date Fri, 20 Aug 2010 00:32:44 -0400
parents 163bf9b2fd13
children 5ed873917c34
comparison
equal deleted inserted replaced
0:163bf9b2fd13 1:6d9bdaf919f7
23 (set! *print-length* 20) 23 (set! *print-length* 20)
24 24
25 25
26 (def img "/home/r/graster/test.png") 26 (def img "/home/r/graster/test.png")
27 27
28
29 (def feed 120)
30 (def dpi [500, 500])
31 (def on_range [0.0, 0.5])
32 (def overshoot 0.5)
33 (def offset [1.0, 1.0])
34 (def tiles [1, 1])
35 (def tile_size [false, false])
36 (def tile_spacing [0.125, 0.125])
37 (def feed 120)
38 (def cut_feed 20)
39 (def corner_radius 0)
40
41
42
43
44 (defn raster-preamble []
45 (str-join \newline
46 ["M63 P0\nG61"
47 (str \F feed)
48 "M101"
49 "M3 S1"]))
50
51
52
28 (defn frame-hash 53 (defn frame-hash
29 "yields a convienent representation for the pixles in an image. 54 "yields a convienent representation for the pixles in an image.
30 Because of the size of the structvre generated, this must only be used 55 Because of the size of the structvre generated, this must only be used
31 in a transient way so that java can do it's garbage collection." 56 in a transient way so that java can do it's garbage collection."
32 [#^java.lang.String image-name] 57 [#^java.lang.String image-name]
44 :g (bit-shift-right (bit-and 0x00ff00 data) 8) 69 :g (bit-shift-right (bit-and 0x00ff00 data) 8)
45 :b (bit-and 0x0000ff data)))))))) 70 :b (bit-and 0x0000ff data))))))))
46 {:width (.getWidth image+) :height (.getHeight image+)}))) 71 {:width (.getWidth image+) :height (.getHeight image+)})))
47 72
48 73
74 (def white {:r 255, :g 255, :b 255})
75 (def black {:r 0, :g 0, :b 0})
76
77 (def expt #(Math/pow %1 %2))
78
79 (defn rgb-euclidian
80 [{r1 :r g1 :g b1 :b} {r2 :r g2 :g b2 :b} ]
81 (expt (+ (expt (- r1 r2) 2)
82 (expt (- g1 g2) 2)
83 (expt (- b1 b2) 2)) 0.5))
84
85 (defn b&w
86 "turn everything strictly black or white"
87 [window]
88 (with-meta
89 (zipmap
90 (keys window)
91 (map (fn [rgb]
92 (if (> (rgb-euclidian rgb white) (rgb-euclidian rgb black))
93 black white))
94 (vals window))) (meta window)))
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
49 (defn frame-hash->bufferedImage 110 (defn frame-hash->bufferedImage
50 [frame-hash] 111 [frame-hash]
51 (let [data (meta frame-hash) 112 (let [data (meta frame-hash)
52 image (BufferedImage. (:width data) (:height data) BufferedImage/TYPE_INT_BGR)] 113 image (BufferedImage. (:width data) (:height data) BufferedImage/TYPE_INT_BGR)]
53 114