Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.96 KB | None | 0 0
  1. (ns cljgame.core
  2.   (:use rosado.processing)
  3.   (:import (javax.swing JFrame))
  4.   (:import (processing.core PApplet))
  5.   (:gen-class))
  6.  
  7. (defprotocol Drawable
  8.   "A protocol for drawable objects"
  9.   (draw [this] "The method to override for drawing."))
  10.  
  11. (defrecord Circle [position radius]
  12.   Drawable
  13.   (draw [_] (ellipse (first position) (second position) (* radius 2) (* radius 2))))
  14.  
  15. (def my-circle (Circle. [20 20] 15))
  16.  
  17. (defn draw-background [r g b]
  18.   "Draw the background"
  19.   (background-float r g b))
  20.  
  21. (def applet
  22.      (proxy [PApplet] []
  23.        (setup []
  24.           (binding [*applet* this]
  25.         (size 200 200)
  26.         (smooth)
  27.         (no-stroke)
  28.         (fill 226)
  29.         (framerate 10)))
  30.        (draw []
  31.          (binding [*applet* this]
  32.            (draw-background 0 0 0)
  33.            (draw my-circle)))))
  34.  
  35. (def swing-frame (JFrame. "CljGame"))
  36.  
  37. (defn -main [& args]
  38.   (.init applet)
  39.   (doto swing-frame
  40.     (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
  41.     (.setSize 200 200)
  42.     (.add applet)
  43.     (.pack)
  44.     (.show)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement