Mercurial > lasercutter
diff src/laser/rasterize.clj @ 11:f952052e37b7
trying a fix.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 24 Aug 2010 19:06:45 -0400 |
parents | 0f48db8d2a05 |
children | 397ab24b4952 |
line wrap: on
line diff
1.1 --- a/src/laser/rasterize.clj Sat Aug 21 06:25:44 2010 -0400 1.2 +++ b/src/laser/rasterize.clj Tue Aug 24 19:06:45 2010 -0400 1.3 @@ -13,14 +13,14 @@ 1.4 (import '(java.io BufferedReader InputStreamReader)) 1.5 (import '(java.awt.image BufferedImage)) 1.6 1.7 -(use 'clojure.contrib.str-utils) 1.8 -(use 'clojure.contrib.seq-utils) 1.9 -(use 'clojure.contrib.combinatorics) 1.10 -(use 'clojure.contrib.duck-streams) 1.11 +;(use 'clojure.contrib.str-utils) 1.12 +;(use 'clojure.contrib.seq-utils) 1.13 +;(use 'clojure.contrib.combinatorics) 1.14 +;(use 'clojure.contrib.duck-streams) 1.15 1.16 -(use 'clojure.contrib.repl-utils) 1.17 +;(use 'clojure.contrib.repl-utils) 1.18 1.19 -(set! *print-length* 20) 1.20 +;(set! *print-length* 20) 1.21 1.22 1.23 1.24 @@ -77,7 +77,7 @@ 1.25 (def white {:r 255, :g 255, :b 255}) 1.26 (def black {:r 0, :g 0, :b 0}) 1.27 1.28 -(def expt #(Math/pow %1 %2)) 1.29 + 1.30 1.31 (defn rgb-euclidian 1.32 [{r1 :r g1 :g b1 :b} {r2 :r g2 :g b2 :b} ] 1.33 @@ -205,34 +205,40 @@ 1.34 ; (println prevoius) 1.35 ; (println range-start) 1.36 (if (<= new-n (+ prevoius 1)) 1.37 - (do ;(println "join") 1.38 + (do ;(println "join") 1.39 ;(println (butlast collection)) 1.40 - (conj (apply vector (butlast collection)) (vector range-start new-n))) 1.41 - (conj collection (vector new-n new-n))))) 1.42 + (conj (apply vector (butlast collection)) 1.43 + (vector range-start new-n))) 1.44 + (conj collection (vector new-n new-n))))) 1.45 1.46 base 1.47 - (map first row)))) 1.48 + (map first row)))) 1.49 + 1.50 1.51 1.52 1.53 (defn row->gmask [[x-dpi y-dpi] forward? row] 1.54 +; (println forward?) 1.55 + (let [start (float (* (/ x-dpi) (first (first 1.56 + (if forward? 1.57 + (reverse row) row)))))] 1.58 1.59 - (let [start (float (* (/ x-dpi) (first (first row))))] 1.60 - 1.61 - (let [preamble (if forward? 1.62 - (str 1.63 + (let [preamble (if-not forward? 1.64 (format "0 0 0 %.3f\n" start) 1.65 - (format "0 0 1 %.3f\n" start))) 1.66 + (format "0 0 1 %.3f\n" start)) 1.67 body 1.68 - (for [[x y] (gather-row row)] 1.69 + (for [[x y] 1.70 + (if forward? 1.71 + (reverse (gather-row row)) 1.72 + (gather-row row))] 1.73 (let [x (float (* x (/ x-dpi))) 1.74 y (float (* y (/ x-dpi)))] 1.75 - (if forward? 1.76 + (if-not forward? 1.77 (str (format "0 0 1 %.3f\n" x) 1.78 (format "0 1 1 %.3f\n" y)) 1.79 1.80 - (str (format "0 0 0 %.3f\n" x) 1.81 - (format "0 1 0 %.3f\n" y)))))] 1.82 + (str (format "0 0 0 %.3f\n" y) 1.83 + (format "0 1 0 %.3f\n" x)))))] 1.84 1.85 (str preamble (str-join "" body))))) 1.86 1.87 @@ -251,9 +257,10 @@ 1.88 1.89 (str "1 0 0 0\n" 1.90 (str-join "" (map (fn [[index row]] 1.91 - (row->gmask dpi (odd? index) row)) 1.92 + (row->gmask dpi (even? index) row)) 1.93 (indexed (make-rows pic)))))) 1.94 1.95 + 1.96 ;; 1 0 0 0 1.97 ;; 0 0 1 2.881 1.98 ;; 0 0 0 2.881 1.99 @@ -302,7 +309,26 @@ 1.100 (spit "/home/r/kevin/out.gmask" (generate-gmask image)) 1.101 image)) 1.102 1.103 - 1.104 + 1.105 + 1.106 +(defn update-state [] 1.107 +(def sing "/home/r/lasercutter/graster/signer4laser2x1.png") 1.108 + 1.109 +(def pic (frame-hash (let [image (ImagePlus. sing)] 1.110 + (.rotate (.getChannelProcessor image) 180) 1.111 + image))) 1.112 + 1.113 +(def pic (b&w pic))) 1.114 + 1.115 + 1.116 + 1.117 + 1.118 + 1.119 + 1.120 + 1.121 + 1.122 + 1.123 + 1.124 1.125 ;;;; testing 1.126 1.127 @@ -339,6 +365,6 @@ 1.128 (.start 1.129 (Thread. 1.130 (fn [] 1.131 - (with-bindings {#'clojure.core/*out* temp} 1.132 + (with-bindings {#'*out* temp} 1.133 (Thread/sleep 5000) 1.134 (println "hi")))))))