Demonstrate nesting
This commit is contained in:
parent
edeb5189cf
commit
7204b221ee
|
@ -6,7 +6,7 @@
|
|||
data/queue
|
||||
lux/chaos)
|
||||
|
||||
(struct gui (events-box fps drawer frame refresh!)
|
||||
(struct gui (depth-box events-box fps drawer frame refresh!)
|
||||
#:methods gen:chaos
|
||||
[(define (chaos-fps c)
|
||||
(gui-fps c))
|
||||
|
@ -22,7 +22,15 @@
|
|||
(set-box! (gui-drawer c) o)
|
||||
((gui-refresh! c)))
|
||||
(define (chaos-label! c l)
|
||||
(send (gui-frame c) set-label l))])
|
||||
(send (gui-frame c) set-label l))
|
||||
(define (chaos-swap! c t)
|
||||
(define db (gui-depth-box c))
|
||||
(define og (unbox db))
|
||||
(set-box! db (add1 og))
|
||||
(begin0 (t)
|
||||
(if (zero? og)
|
||||
(send (gui-frame c) show #f)
|
||||
(set-box! db og))))])
|
||||
|
||||
(define (make-gui fps
|
||||
#:mode [mode 'draw]
|
||||
|
@ -75,9 +83,12 @@
|
|||
(define (refresh!)
|
||||
(send c refresh))
|
||||
|
||||
(send f center)
|
||||
(send f show #t)
|
||||
|
||||
(gui events-box fps drawer f refresh!))
|
||||
(define depth-box (box 0))
|
||||
|
||||
(gui depth-box events-box fps drawer f refresh!))
|
||||
|
||||
(provide
|
||||
(contract-out
|
||||
|
|
|
@ -43,6 +43,9 @@
|
|||
|
||||
(define (key-state-set? ks kc)
|
||||
(hash-ref (key-state-keys ks) kc #f))
|
||||
(define (key-state-set?! ks kc)
|
||||
(begin0 (key-state-set? ks kc)
|
||||
(hash-set! (key-state-keys ks) kc #f)))
|
||||
|
||||
(provide
|
||||
(contract-out
|
||||
|
@ -63,5 +66,8 @@
|
|||
(-> key-state? (is-a?/c key-event%)
|
||||
any)]
|
||||
[key-state-set?
|
||||
(-> key-state? (or/c char? key-code-symbol?)
|
||||
boolean?)]
|
||||
[key-state-set?!
|
||||
(-> key-state? (or/c char? key-code-symbol?)
|
||||
boolean?)]))
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
(define COLORS
|
||||
'("red" "orange" "yellow" "green" "blue" "indigo" "violet"))
|
||||
|
||||
(struct spin (ks ms color frame)
|
||||
(struct spin (layer ks ms color frame)
|
||||
#:methods gen:word
|
||||
[(define (word-label s ft)
|
||||
(lux-standard-label "Spin!" ft))
|
||||
(define (word-tick w es)
|
||||
(match-define (spin ks ms color f) w)
|
||||
(match-define (spin layer ks ms color f) w)
|
||||
(define closed? #f)
|
||||
(for ([e es])
|
||||
(match e
|
||||
|
@ -28,25 +28,33 @@
|
|||
(key-state-update! ks ke)]))
|
||||
(define x (mouse-state-x ms))
|
||||
(define y (mouse-state-y ms))
|
||||
(when (key-state-set? ks #\space)
|
||||
(when (key-state-set?! ks #\space)
|
||||
(set! color (fxmodulo (fx+ 1 color) (length COLORS))))
|
||||
(match closed?
|
||||
(when (key-state-set?! ks #\return)
|
||||
(spin-it! (add1 layer)))
|
||||
(match (or closed?
|
||||
(key-state-set?! ks 'escape))
|
||||
[#t
|
||||
(values #f w)]
|
||||
[#f
|
||||
(values (spin ks ms color (fxmodulo (fx+ f 1) 360))
|
||||
(values (spin layer ks ms color (fxmodulo (fx+ f 1) 360))
|
||||
(lambda (width height dc)
|
||||
(send dc set-background (list-ref COLORS color))
|
||||
(send dc clear)
|
||||
(send dc set-rotation (* (/ f 360) 2 3.14))
|
||||
(send dc set-origin x y)
|
||||
(send dc draw-text "Spinning!" 0 0)))]))])
|
||||
(send dc draw-text (format "~a: Spinning!" layer) 0 0)))]))])
|
||||
|
||||
(module+ main
|
||||
(define s
|
||||
(spin (make-key-state)
|
||||
(define (spin-it! layer)
|
||||
(define s
|
||||
(spin layer
|
||||
(make-key-state)
|
||||
(make-mouse-state)
|
||||
0 0))
|
||||
(fiat-lux s))
|
||||
|
||||
(module+ main
|
||||
(call-with-chaos
|
||||
(make-gui 60.0)
|
||||
(λ () (fiat-lux s))))
|
||||
(λ ()
|
||||
(spin-it! 0))))
|
||||
|
|
Loading…
Reference in New Issue