comparison src/laser/rasterize.clj @ 13:397ab24b4952

saving, to update with correct fix later
author Robert McIntyre <rlm@mit.edu>
date Sun, 29 Aug 2010 00:03:09 -0400
parents f952052e37b7
children db745c95aabd
comparison
equal deleted inserted replaced
12:aadb93318584 13:397ab24b4952
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 (defn row->gcode [[x-dpi y-dpi] row]
185 (let [[x1 y1] (first row) 185 (let [[x1 y1] (first row)
186 [x2 y2] (last row)] 186 [x2 y2] (last row)
187 x2 (+ x2 (* x-dpi 0.318))]
188
189
190 ; (println x2)
187 (str (format "G0 X%.3f Y%.3f\n" 191 (str (format "G0 X%.3f Y%.3f\n"
188 (float (* x1 (/ x-dpi))) 192 (float (* x1 (/ x-dpi)))
189 (float (* y1 (/ y-dpi)))) 193 (float (* y1 (/ y-dpi))))
190 194
191 (format "G1 X%.3f Y%.3f\n" 195 (format "G1 X%.3f Y%.3f\n"
230 (for [[x y] 234 (for [[x y]
231 (if forward? 235 (if forward?
232 (reverse (gather-row row)) 236 (reverse (gather-row row))
233 (gather-row row))] 237 (gather-row row))]
234 (let [x (float (* x (/ x-dpi))) 238 (let [x (float (* x (/ x-dpi)))
235 y (float (* y (/ x-dpi)))] 239 y (float (* y (/ x-dpi)))
240 x (+ x 0.159)];; shift by a small margin.
236 (if-not forward? 241 (if-not forward?
237 (str (format "0 0 1 %.3f\n" x) 242 (str (format "0 0 1 %.3f\n" x)
238 (format "0 1 1 %.3f\n" y)) 243 (format "0 1 1 %.3f\n" y))
239 244
240 (str (format "0 0 0 %.3f\n" y) 245 (str (format "0 0 0 %.3f\n" y)
243 (str preamble (str-join "" body))))) 248 (str preamble (str-join "" body)))))
244 249
245 250
246 251
247 (defn make-rows [pic] 252 (defn make-rows [pic]
248
249 (map (partial sort #(< (first %1) (first %2))) 253 (map (partial sort #(< (first %1) (first %2)))
250 (partition-by last 254 (partition-by last
251 (sort (fn [[x1 y1][x2 y2]] (> y2 y1)) 255 (sort (fn [[x1 y1][x2 y2]] (> y2 y1))
252 (map first (filter-vals (partial = black) pic)))))) 256 (map first (filter-vals (partial = black) pic))))))
253 257
366 (Thread. 370 (Thread.
367 (fn [] 371 (fn []
368 (with-bindings {#'*out* temp} 372 (with-bindings {#'*out* temp}
369 (Thread/sleep 5000) 373 (Thread/sleep 5000)
370 (println "hi"))))))) 374 (println "hi")))))))
375
376
377 (comment
378 (do
379 (require 'rlm.quick)
380 (ns laser.rasterize)
381 (rlm.quick/dirty)
382 (use :reload-all 'laser.rasterize)
383 (undef map-keys)
384 (use :reload-all 'laser.rasterize)))