Piccolo2D with Clojure

14 views
Skip to first unread message

Travis

unread,
Oct 12, 2009, 12:12:20 PM10/12/09
to Piccolo2D Users
I thought it might be interesting for others to see what it looks like
to write a program using Piccolo2D in Clojure. This is almost the same
as some code posted on the website.


(ns tw.HelloWorld
(:gen-class
:extends javax.swing.JFrame
:init init
:state state
:methods [[st [] clojure.lang.PersistentArrayMap]])
(:import
(edu.umd.cs.piccolo
PNode
PCanvas)
(edu.umd.cs.piccolo.nodes
PText)
(java.awt Color)
(edu.umd.cs.piccolo.event PDragEventHandler)
(javax.swing JFrame)
)
)

(defn -init []
[["Piccolo2D Hello-World"] {
:canvas (PCanvas.)
:text (PText. "Hello World")
}]
)

(defn -st [this]
(.state this))

(defn -main [& args]
(let [
hw (new tw.HelloWorld)
state (.st hw)
canvas (state :canvas)
text (state :text)
anotherNode (doto (PNode.)
(.setBounds 0 0 100 80)
(.setPaint (Color/YELLOW)))
aNode (doto (PNode.)
(.setBounds 0 0 100 80)
(.setPaint (Color/RED))
(.addChild anotherNode)
(.translate 100 100)
(.scale (float 1.5))
(.rotate 45)
)
layer (doto (.getLayer canvas)
(.addChild text)
(.addChild aNode)
)
]
(doto canvas
(.setPanEventHandler nil)
(.addInputEventListener (PDragEventHandler.)))
(doto hw
(.add canvas)
(.setDefaultCloseOperation (JFrame/EXIT_ON_CLOSE))
(.setSize 600 400)
(.setVisible true)
)
))

Reply all
Reply to author
Forward
0 new messages