# HG changeset patch # User Robert McIntyre # Date 1327036764 25200 # Node ID 9d0fe7f54e146535e1cedef811322edd616d49f1 # Parent a980462ebe76dfc001a7c7cb1e30323b9bc77cd8 merged image viewing code to cortex.util diff -r a980462ebe76 -r 9d0fe7f54e14 org/eyes.org --- a/org/eyes.org Thu Jan 19 22:08:46 2012 -0700 +++ b/org/eyes.org Thu Jan 19 22:19:24 2012 -0700 @@ -119,34 +119,6 @@ (:import com.jme3.scene.Node) (:import com.jme3.math.Vector3f)) -(defn view-image - "Initailizes a JPanel on which you may draw a BufferedImage. - Returns a function that accepts a BufferedImage and draws it to the - JPanel." - [] - (let [image - (atom - (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) - panel - (proxy [JPanel] [] - (paint - [graphics] - (proxy-super paintComponent graphics) - (.drawImage graphics @image 0 0 nil))) - frame (JFrame. "Display Image")] - (SwingUtilities/invokeLater - (fn [] - (doto frame - (-> (.getContentPane) (.add panel)) - (.pack) - (.setLocationRelativeTo nil) - (.setResizable true) - (.setVisible true)))) - (fn [#^BufferedImage i] - (reset! image i) - (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i))) - (.repaint panel 0 0 (.getWidth i) (.getHeight i))))) - (defn test-two-eyes "Testing vision: Tests the vision system by creating two views of the same rotating diff -r a980462ebe76 -r 9d0fe7f54e14 org/test-creature.org --- a/org/test-creature.org Thu Jan 19 22:08:46 2012 -0700 +++ b/org/test-creature.org Thu Jan 19 22:19:24 2012 -0700 @@ -67,34 +67,6 @@ (declare joint-create) (use 'clojure.contrib.def) -(defn view-image - "Initailizes a JPanel on which you may draw a BufferedImage. - Returns a function that accepts a BufferedImage and draws it to the - JPanel." - [] - (let [image - (atom - (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) - panel - (proxy [JPanel] [] - (paint - [graphics] - (proxy-super paintComponent graphics) - (.drawImage graphics @image 0 0 nil))) - frame (JFrame. "Display Image")] - (SwingUtilities/invokeLater - (fn [] - (doto frame - (-> (.getContentPane) (.add panel)) - (.pack) - (.setLocationRelativeTo nil) - (.setResizable true) - (.setVisible true)))) - (fn [#^BufferedImage i] - (reset! image i) - (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i))) - (.repaint panel 0 0 (.getWidth i) (.getHeight i))))) - (defn points->image "Take a sparse collection of points and visuliaze it as a BufferedImage." diff -r a980462ebe76 -r 9d0fe7f54e14 org/util.org --- a/org/util.org Thu Jan 19 22:08:46 2012 -0700 +++ b/org/util.org Thu Jan 19 22:19:24 2012 -0700 @@ -94,19 +94,22 @@ (:import com.jme3.scene.shape.Sphere) (:import com.jme3.light.AmbientLight) (:import com.jme3.light.DirectionalLight) - (:import com.jme3.math.ColorRGBA) + (:import (com.jme3.math Triangle ColorRGBA)) (:import com.jme3.bullet.BulletAppState) (:import com.jme3.material.Material) (:import com.jme3.scene.Geometry) + (:import java.awt.image.BufferedImage) + (:import javax.swing.JPanel) + (:import javax.swing.JFrame) + (:import javax.swing.SwingUtilities) + (:import (java.util.logging Level Logger))) - - (defvar println-repl (bound-fn [& args] (apply println args)) "println called from the LWJGL thread will not go to the REPL, but - instead to whatever terminal started the JVM process. This function - will always output to the REPL") + instead to whatever terminal started the JVM process. This function + will always output to the REPL") (defn position-camera "Change the position of the in-world camera." @@ -388,6 +391,34 @@ #+begin_src clojure :results silent (in-ns 'cortex.util) +(defn view-image + "Initailizes a JPanel on which you may draw a BufferedImage. + Returns a function that accepts a BufferedImage and draws it to the + JPanel." + [] + (let [image + (atom + (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) + panel + (proxy [JPanel] [] + (paint + [graphics] + (proxy-super paintComponent graphics) + (.drawImage graphics @image 0 0 nil))) + frame (JFrame. "Display Image")] + (SwingUtilities/invokeLater + (fn [] + (doto frame + (-> (.getContentPane) (.add panel)) + (.pack) + (.setLocationRelativeTo nil) + (.setResizable true) + (.setVisible true)))) + (fn [#^BufferedImage i] + (reset! image i) + (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i))) + (.repaint panel 0 0 (.getWidth i) (.getHeight i))))) + (defprotocol Viewable (view [something]))