-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrow.rkt
38 lines (31 loc) · 919 Bytes
/
crow.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#lang racket/base
(require racket/contract
(except-in 2htdp-raven/universe state)
"input.rkt"
"test-data.rkt"
"vn-gen.rkt")
(define (init)
(crow-state (vn-gen test-pages)
page-handle-key
page-handle-mouse))
(define (render s)
(define ctx*img ((crow-state-text-gen s) 'render))
(set-crow-state-on-mouse! s (vn-ctx-on-mouse ctx*img))
(set-crow-state-on-key! s (vn-ctx-on-key ctx*img))
(vn-ctx-image ctx*img))
(define (tick s)
((crow-state-text-gen s) 'tick)
s)
(define/contract (dispatch-handle-key s k)
handle-key/c
(define on-key (crow-state-on-key s))
(on-key s k))
(define/contract (dispatch-handle-mouse s x y evt)
handle-mouse/c
(define on-mouse (crow-state-on-mouse s))
(on-mouse s x y evt))
(big-bang (init)
[to-draw render]
[on-key dispatch-handle-key]
[on-mouse dispatch-handle-mouse]
[on-tick tick 1/15])