Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add #'mouse-x, #'mouse-y fns. Update mouse example; fixes #17

  • Loading branch information...
commit 0e94a58865132233f8d4689b78ce37bca1e5bc92 1 parent 935a65c
@rosado authored
View
7 examples/example2.clj
@@ -1,5 +1,3 @@
-;; processing example
-
(ns example2
(:use [processing.core]
[processing.core.applet]))
@@ -27,7 +25,6 @@
(defn setup []
"Runs once."
- (size 200 200)
(smooth)
(no-stroke)
(fill 226)
@@ -41,6 +38,4 @@
:draw draw
:size [200 200])
-(run example2)
-
-;; (stop example2)
+(applet-start example2)
View
22 examples/mouse.clj
@@ -1,8 +1,6 @@
-;; processing example
-
(ns mouse-example
(:use [processing.core]
- [processing.core.applet]))
+ [processing.core.applet]))
(def mouse-position (atom [0 0]))
@@ -15,22 +13,18 @@
(point x y)))
(defn setup []
- (size 200 200)
(smooth)
(no-stroke))
-
-(defn mouse-moved [evt]
- (let [x (.getX evt) y (.getY evt)]
+(defn mouse-moved []
+ (let [x (mouse-x) y (mouse-y)]
(reset! mouse-position [x y])))
-;; Now we just need to define an applet:
-
-(defapplet mouse-example :title "Mouse example."
+(defapplet mouse-example
+ :title "Mouse example."
:size [200 200]
- :setup setup :draw draw
+ :setup setup
+ :draw draw
:mouse-moved mouse-moved)
-(run mouse-example)
-
-;; (stop mouse-example)
+(applet-start mouse-example)
View
51 examples/with_proxy.clj
@@ -1,51 +0,0 @@
-;; processing test
-
-(ns p5-example
- (:use processing.core)
- (:import (javax.swing JFrame))
- (:import (processing.core PApplet)))
-
-
-;; here's a function which will be called by Processing's (PApplet)
-;; draw method every frame. Place your code here. If you eval it
-;; interactively, you can redefine it while the applet is running and
-;; see effects immediately
-
-(defn fancy-draw
- "An example of a function which does *something*."
- [dst]
- (background-float (rand-int 256) (rand-int 256) (rand-int 256))
- (fill-float (rand-int 125) (rand-int 125) (rand-int 125))
- (ellipse 100 100 (rand-int 90) (rand-int 90))
- (stroke-float 10)
- (line 10 10 (rand-int 150) (rand-int 150))
- (no-stroke)
- (display-filter :invert)
- (frame-rate 10))
-
-;; below, we create an PApplet proxy and override setup() and draw()
-;; methods. Then we put the applet into a window and display it.
-
-(def p5-applet
- (proxy [PApplet] []
- (setup []
- (binding [*applet* this]
- (size 200 200)
- (smooth)
- (no-stroke)
- (fill 226)
- (frame-rate 10)))
- (draw []
- (binding [*applet* this]
- (fancy-draw this)))))
-
-(.init p5-applet)
-
-(def swing-frame (JFrame. "Processing with Clojure"))
-(doto swing-frame
- (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
- (.setSize 200 200)
- (.add p5-applet)
- (.pack)
- (.show))
-
View
10 src/processing/core.clj
@@ -901,6 +901,16 @@
;; $$nfp
;; $$nfs
+(defn mouse-x
+ "Current horizontal coordinate of the mouse."
+ []
+ (. *applet* :mouseX))
+
+(defn mouse-y
+ "Current vertical coordinate of the mouse."
+ []
+ (. *applet* :mouseY))
+
(defn no-cursor [] (.noCursor *applet*))
(defn no-fill
Please sign in to comment.
Something went wrong with that request. Please try again.