Mercurial > rlm
view src/rlm/visualize.clj @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children | 12d1367cf1aa |
line wrap: on
line source
1 (ns rlm.visualize2 "this namespace has only one purpose -- to enable3 visual display of as many data structures as possible,4 with a focus on image processing (for example, raw integers5 will be shown as the color which they would encode in a RGBA6 BufferedImage. I want to get as many types as I can in here."7 {:author "Robert McIntyre"}9 (:import java.awt.image.BufferedImage10 [ij ImagePlus IJ]))12 (defmulti visual (fn [& args] (class (last args))))14 (import '[org.scilab.forge.jlatexmath TeXConstants TeXFormula TeXIcon])15 (import java.awt.Insets)16 (import javax.swing.JLabel)17 (import java.awt.Color)20 (defmethod visual ImagePlus21 [image]22 (.show image)23 image)25 (defmethod visual (class 4)26 [color]27 (let [image (BufferedImage. 200 200 BufferedImage/TYPE_INT_RGB)]28 (doall (for [y (range 200) x (range 200)] (.setRGB image x y color)))29 (visual (ImagePlus. "color display" image))))31 (defmethod visual BufferedImage32 [image]33 (visual (ImagePlus. "visual" image)))36 (defmethod visual TeXFormula37 [formula]38 (let [icon39 (doto (.createTeXIcon formula TeXConstants/STYLE_DISPLAY 30)40 (.setInsets (Insets. 5 5 5 5)))41 image (BufferedImage. (.getIconWidth icon) (.getIconHeight icon)42 BufferedImage/TYPE_INT_ARGB)43 g (.createGraphics image)44 jl (JLabel.)]45 (.setForeground jl (Color. 0 0 0))46 (.setColor g Color/white)47 (.fillRect g 0 0 (.getIconWidth icon) (.getIconHeight icon))48 (.paintIcon icon jl g 0 0)49 (visual image)))