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