Mercurial > rlm
diff src/rlm/cool_shapes.clj @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/rlm/cool_shapes.clj Tue Oct 18 00:57:08 2011 -0700 1.3 @@ -0,0 +1,66 @@ 1.4 +(ns rlm.cool-shapes 1.5 + "I just couldn't resist playing around with the Shape 1.6 + library in Clojure. This namespace samples images 1.7 + and creates a Grid object containg many small circles 1.8 + of different colors, one for each sampled pixel 1.9 + 1.10 + I'm submitting this late just to show offwhat I was 1.11 + working on --- I don't expect it to be graded. 1.12 + 1.13 + LATE-Heart-Blending.jpg is the source, 1.14 + Late-heart-output is the sampled output." 1.15 + {:author "Robert McIntyre"} 1.16 + (:import [shapes 1.17 + Circle 1.18 + Colored 1.19 + Grid 1.20 + Horizontal 1.21 + Layered 1.22 + Polygon 1.23 + Scaled 1.24 + Vertical 1.25 + Rotated] 1.26 + 1.27 + [core 1.28 + JPS 1.29 + CurrentPoint 1.30 + RotationAngle] 1.31 + 1.32 + [visitors PostscriptVisitor] 1.33 + [java.awt Color] 1.34 + [ij ImagePlus IJ] 1.35 + [ij.process ImageProcessor ColorProcessor])) 1.36 + 1.37 +(defn output 1.38 + "send a shape to ~/Desktop/output.ps for 1.39 + debugging purposes" 1.40 + [shape] 1.41 + (clojure.contrib.duck-streams/spit 1.42 + (clojure.contrib.duck-streams/file-str 1.43 + "~/Desktop/output.ps") 1.44 + (JPS/postscript shape 400 400))) 1.45 + 1.46 +(defn bubbles 1.47 + "take an image and \"bubbleize\" it --- replace 1.48 + the pixels with small sampled circles" 1.49 + [#^ImagePlus image accuracy radius] 1.50 + (reduce 1.51 + (fn [grid [color x y]] 1.52 + (.addShape grid 1.53 + (Colored. color (Circle. radius)) 1.54 + x y)) 1.55 + (Grid.) 1.56 + (for [y (range 0 (.getHeight image) accuracy) 1.57 + x (range 0 (.getWidth image) accuracy)] 1.58 + 1.59 + [(Color. (.getRGB (.getImage image) x y)) 1.60 + x y]))) 1.61 + 1.62 +(defn show-bubbles [#^ImagePlus image radius acc] 1.63 + (output (Rotated. 1.64 + (Scaled. (bubbles image acc radius) 1.65 + 0.7 1.66 + 0.7) 1.67 + RotationAngle/Rotate180))) 1.68 + 1.69 +