diff 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
line wrap: on
line diff
     1.1 --- a/src/laser/rasterize.clj	Thu Aug 19 22:24:41 2010 -0400
     1.2 +++ b/src/laser/rasterize.clj	Fri Aug 20 00:32:44 2010 -0400
     1.3 @@ -25,6 +25,31 @@
     1.4  
     1.5  (def img "/home/r/graster/test.png")
     1.6  
     1.7 +
     1.8 +(def feed 120)
     1.9 +(def  dpi [500, 500])
    1.10 +(def on_range [0.0, 0.5])
    1.11 +(def overshoot 0.5)
    1.12 +(def offset [1.0, 1.0])
    1.13 +(def tiles [1, 1])
    1.14 +(def tile_size [false, false])
    1.15 +(def tile_spacing [0.125, 0.125])
    1.16 +(def feed 120)
    1.17 +(def cut_feed 20)
    1.18 +(def corner_radius 0)
    1.19 +
    1.20 +
    1.21 +
    1.22 +
    1.23 +(defn raster-preamble []
    1.24 +  (str-join \newline
    1.25 +	    ["M63 P0\nG61"
    1.26 +	    (str \F feed)
    1.27 +	    "M101"
    1.28 +	    "M3 S1"]))
    1.29 +
    1.30 +
    1.31 +
    1.32  (defn frame-hash
    1.33    "yields a convienent representation for the pixles in an image.
    1.34     Because of the size of the structvre generated, this must only be used
    1.35 @@ -46,6 +71,42 @@
    1.36        {:width  (.getWidth image+) :height (.getHeight image+)})))
    1.37  
    1.38  
    1.39 +(def white {:r 255, :g 255, :b 255})
    1.40 +(def black {:r 0,   :g 0,   :b 0})
    1.41 +
    1.42 +(def expt #(Math/pow %1 %2))
    1.43 +
    1.44 +(defn rgb-euclidian
    1.45 +  [{r1 :r g1 :g b1 :b} {r2 :r g2 :g b2 :b} ]
    1.46 +  (expt (+ (expt (- r1 r2) 2)
    1.47 +	  (expt (- g1 g2) 2)
    1.48 +	  (expt (- b1 b2) 2)) 0.5))
    1.49 +
    1.50 +(defn b&w
    1.51 +  "turn everything strictly black or white"
    1.52 +  [window]
    1.53 +  (with-meta
    1.54 +  (zipmap
    1.55 +   (keys window)
    1.56 +   (map (fn  [rgb] 
    1.57 +	  (if (> (rgb-euclidian rgb white) (rgb-euclidian rgb black))
    1.58 +	    black white))
    1.59 +	(vals window))) (meta window)))
    1.60 +
    1.61 +
    1.62 +
    1.63 +
    1.64 +
    1.65 +  
    1.66 +  
    1.67 +
    1.68 +
    1.69 +
    1.70 +
    1.71 +
    1.72 +
    1.73 +
    1.74 +
    1.75  (defn frame-hash->bufferedImage
    1.76    [frame-hash]
    1.77      (let [data  (meta frame-hash)