comparison src/laser/rasterize.clj @ 14:db745c95aabd

trying to revert back to a usable form
author Robert McIntyre <rlm@mit.edu>
date Sun, 29 Aug 2010 00:09:28 -0400
parents 397ab24b4952
children 8ad629298649
comparison
equal deleted inserted replaced
13:397ab24b4952 14:db745c95aabd
179 ;(defn span [row] 179 ;(defn span [row]
180 ; (let [sorted-row (sort #(< (first %1) (first %2)) row)] 180 ; (let [sorted-row (sort #(< (first %1) (first %2)) row)]
181 ; (vector (first sorted-row) (last sorted-row)))) 181 ; (vector (first sorted-row) (last sorted-row))))
182 182
183 183
184 (defn row->gcode [[x-dpi y-dpi] row] 184
185 (let [[x1 y1] (first row) 185 (defn row->gcode [[x-dpi y-dpi] forward? row]
186 [x2 y2] (last row) 186
187 x2 (+ x2 (* x-dpi 0.318))] 187 (let [[x1 y1] (if forward? (last row) (first row))
188 [x2 y2] (if forward? (first row) (last row))]
189
190
191 ; (let [[x1 y1] (first row)
192 ; [x2 y2] (last row)
193 ; x2 (+ x2 (* x-dpi 0.318))]
188 194
189 195
190 ; (println x2) 196 ; (println x2)
191 (str (format "G0 X%.3f Y%.3f\n" 197 (str (format "G0 X%.3f Y%.3f\n"
192 (float (* x1 (/ x-dpi))) 198 (float (* x1 (/ x-dpi)))
235 (if forward? 241 (if forward?
236 (reverse (gather-row row)) 242 (reverse (gather-row row))
237 (gather-row row))] 243 (gather-row row))]
238 (let [x (float (* x (/ x-dpi))) 244 (let [x (float (* x (/ x-dpi)))
239 y (float (* y (/ x-dpi))) 245 y (float (* y (/ x-dpi)))
240 x (+ x 0.159)];; shift by a small margin. 246 ;; x (+ x 0.159)];; shift by a small margin.
241 (if-not forward? 247 (if-not forward?
242 (str (format "0 0 1 %.3f\n" x) 248 (str (format "0 0 1 %.3f\n" x)
243 (format "0 1 1 %.3f\n" y)) 249 (format "0 1 1 %.3f\n" y))
244 250
245 (str (format "0 0 0 %.3f\n" y) 251 (str (format "0 0 0 %.3f\n" y)
285 291
286 292
287 293
288 (defn generate-gcode [pic] 294 (defn generate-gcode [pic]
289 (str (raster-preamble) 295 (str (raster-preamble)
296
297 (str-join ""
298 (map
299 (fn [index row]
300 (partial row->gcode dpi (even? index)) (indexed (make-rows pic))))
301 (raster-epilogue))))
302
303
290 304
291 305 ; (str-join "" (map (partial row->gcode dpi) (make-rows pic)))
292 (str-join "" (map (partial row->gcode dpi) (make-rows pic))) 306 ; (raster-epilogue)))
293 (raster-epilogue)))
294 307
295 308
296 309
297 (defn rotate [degrees #^ImagePlus image] 310 (defn rotate [degrees #^ImagePlus image]
298 (.rotate (.getChannelProcessor image) degrees) 311 (.rotate (.getChannelProcessor image) degrees)