Advertisement
Guest User

Simple no-loop failure? example

a guest
Oct 29th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Creates a 800x600 field and (is intended) to draw a new 10x10 rectangle after each mouse click
  2. ; Nevertheless..
  3. (ns sample.core
  4.   (:use quil.core))
  5.  
  6. (def cell-size 10)
  7. (def w (* 80 cell-size))
  8. (def h (* 60 cell-size))
  9.  
  10. (def X (atom 0))
  11. (def Y (atom 0))
  12.  
  13. (defn draw []
  14.   (do
  15.     (stroke-weight 1)          
  16.     (stroke 0)
  17.     (fill 255)                
  18.     (swap! X + cell-size)
  19.     (swap! Y + cell-size)
  20.     (rect @X @Y cell-size cell-size)))
  21.  
  22. (defn mouse-handler []  ; We never see this happen
  23.       (redraw) ; This block isn't call at all: After mouse click we neither see the redraw happen
  24.       (println "abacaba") ; Nor any output.
  25. )
  26.  
  27. (defn setup []
  28.   (background 40)
  29.   (no-loop)) ; https://github.com/quil/quil/wiki/no~loop
  30.  
  31. (defn field []
  32.   (sketch
  33.     :title "sample"
  34.     :draw draw
  35.     :setup setup                
  36.     :mouse-pressed mouse-handler ; None of 3 types of possible handlers gives the correct result
  37.     :size [w h]))
  38.  
  39. (field)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement