comparison org/sense.org @ 393:02cc0734a976

extra options.
author Robert McIntyre <rlm@mit.edu>
date Tue, 05 Nov 2013 16:51:15 -0500
parents d37ccb6c888f
children 258078f78b33
comparison
equal deleted inserted replaced
392:bbfdaa42c19a 393:02cc0734a976
255 (defn view-image 255 (defn view-image
256 "Initializes a JPanel on which you may draw a BufferedImage. 256 "Initializes a JPanel on which you may draw a BufferedImage.
257 Returns a function that accepts a BufferedImage and draws it to the 257 Returns a function that accepts a BufferedImage and draws it to the
258 JPanel. If given a directory it will save the images as png files 258 JPanel. If given a directory it will save the images as png files
259 starting at 0000000.png and incrementing from there." 259 starting at 0000000.png and incrementing from there."
260 ([#^File save] 260 ([#^File save title]
261 (let [idx (atom -1) 261 (let [idx (atom -1)
262 image 262 image
263 (atom 263 (atom
264 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) 264 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
265 panel 265 panel
266 (proxy [JPanel] [] 266 (proxy [JPanel] []
267 (paint 267 (paint
268 [graphics] 268 [graphics]
269 (proxy-super paintComponent graphics) 269 (proxy-super paintComponent graphics)
270 (.drawImage graphics @image 0 0 nil))) 270 (.drawImage graphics @image 0 0 nil)))
271 frame (JFrame. "Display Image")] 271 frame (JFrame. title)]
272 (SwingUtilities/invokeLater 272 (SwingUtilities/invokeLater
273 (fn [] 273 (fn []
274 (doto frame 274 (doto frame
275 (-> (.getContentPane) (.add panel)) 275 (-> (.getContentPane) (.add panel))
276 (.pack) 276 (.pack)
283 (.repaint panel 0 0 (.getWidth i) (.getHeight i)) 283 (.repaint panel 0 0 (.getWidth i) (.getHeight i))
284 (if save 284 (if save
285 (ImageIO/write 285 (ImageIO/write
286 i "png" 286 i "png"
287 (File. save (format "%07d.png" (swap! idx inc)))))))) 287 (File. save (format "%07d.png" (swap! idx inc))))))))
288 ([#^File save]
289 (view-image save "Display Image"))
288 ([] (view-image nil))) 290 ([] (view-image nil)))
289 291
290 (defn view-sense 292 (defn view-sense
291 "Take a kernel that produces a BufferedImage from some sense data 293 "Take a kernel that produces a BufferedImage from some sense data
292 and return a function which takes a list of sense data, uses the 294 and return a function which takes a list of sense data, uses the