Mercurial > rlm
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-shapes2 "I just couldn't resist playing around with the Shape3 library in Clojure. This namespace samples images4 and creates a Grid object containg many small circles5 of different colors, one for each sampled pixel7 I'm submitting this late just to show offwhat I was8 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 [shapes14 Circle15 Colored16 Grid17 Horizontal18 Layered19 Polygon20 Scaled21 Vertical22 Rotated]24 [core25 JPS26 CurrentPoint27 RotationAngle]29 [visitors PostscriptVisitor]30 [java.awt Color]31 [ij ImagePlus IJ]32 [ij.process ImageProcessor ColorProcessor]))34 (defn output35 "send a shape to ~/Desktop/output.ps for36 debugging purposes"37 [shape]38 (clojure.contrib.duck-streams/spit39 (clojure.contrib.duck-streams/file-str40 "~/Desktop/output.ps")41 (JPS/postscript shape 400 400)))43 (defn bubbles44 "take an image and \"bubbleize\" it --- replace45 the pixels with small sampled circles"46 [#^ImagePlus image accuracy radius]47 (reduce48 (fn [grid [color x y]]49 (.addShape grid50 (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.763 0.7)64 RotationAngle/Rotate180)))