view 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 source
1 (ns rlm.cool-shapes
2 "I just couldn't resist playing around with the Shape
3 library in Clojure. This namespace samples images
4 and creates a Grid object containg many small circles
5 of different colors, one for each sampled pixel
7 I'm submitting this late just to show offwhat I was
8 working on --- I don't expect it to be graded.
10 LATE-Heart-Blending.jpg is the source,
11 Late-heart-output is the sampled output."
12 {:author "Robert McIntyre"}
13 (:import [shapes
14 Circle
15 Colored
16 Grid
17 Horizontal
18 Layered
19 Polygon
20 Scaled
21 Vertical
22 Rotated]
24 [core
25 JPS
26 CurrentPoint
27 RotationAngle]
29 [visitors PostscriptVisitor]
30 [java.awt Color]
31 [ij ImagePlus IJ]
32 [ij.process ImageProcessor ColorProcessor]))
34 (defn output
35 "send a shape to ~/Desktop/output.ps for
36 debugging purposes"
37 [shape]
38 (clojure.contrib.duck-streams/spit
39 (clojure.contrib.duck-streams/file-str
40 "~/Desktop/output.ps")
41 (JPS/postscript shape 400 400)))
43 (defn bubbles
44 "take an image and \"bubbleize\" it --- replace
45 the pixels with small sampled circles"
46 [#^ImagePlus image accuracy radius]
47 (reduce
48 (fn [grid [color x y]]
49 (.addShape grid
50 (Colored. color (Circle. radius))
51 x y))
52 (Grid.)
53 (for [y (range 0 (.getHeight image) accuracy)
54 x (range 0 (.getWidth image) accuracy)]
56 [(Color. (.getRGB (.getImage image) x y))
57 x y])))
59 (defn show-bubbles [#^ImagePlus image radius acc]
60 (output (Rotated.
61 (Scaled. (bubbles image acc radius)
62 0.7
63 0.7)
64 RotationAngle/Rotate180)))