big-bang 00
Why do handlers have specific signatures?
Application Practice
-
You want to turn
pah
into a key handlerpa
. Write the signature forpa
. Write the new functionpa
.(define pusher-square (square 5 "solid" "transparent")) (define (pah x) (beside pusher-square x))
-
You need to modify the definition of your mouse handler
pm
so that it can be run when you press a key instead of using the mouse. How do you do that?(define (pm img x y event) (rotate 5 img))
-
What kind of handler is the function
pq
appropriate for right now?(define (pq a b c d) (crop-left a 5))
-
Convert the
pq
above to a tick handlerpqt
. Also give the correct signature ofpqt
. -
Use the starter code below to answer the questions.
(define (go-right n) (+ n 5)) (define (go-left n) (- n 5)) (define (draw-bar n) (rectangle n 30 "solid" "purple")) (big-bang 100 (on-mouse go-right-m) (on-key go-left-k) (to-draw draw-bar))
- What is the first “thing” given to the draw handler? What kind of “thing” is it? (That is, what is the type of the “initial model”?)
- Edit the code to change the function
go-right
into a mouse handlergo-right-m
. What is the signature ofgo-right-m
? - Edit the code to change the function
go-left
into a key handler. What is the signature of the key handlergo-left-k
?
-
The animation below is supposed to be a stick figure moving to the right in an empty scene. The code has problems.
- Illustrate the problem by drawing a “three column model/drawing diagram” beginning with the initial model.
- What is wrong with the code below?
- How would you fix it?
The code:
(define (bad-push-right n) (rectangle n 1 "solid" "orange")) (define (bad-draw n) (overlay (beside (rectangle n 1 "solid" "blue") pic:stick-figure) (empty-scene 300 200))) (big-bang 50 (on-tick bad-push-right 0.25) (to-draw bad-draw))