Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require 2htdp/image)
- (require 2htdp/universe)
- ;; A cat that walks from right to left
- ;; =================
- ;; Constants:
- (define WIDTH 600)
- (define HEIGHT 400)
- (define CAT-Y (/ HEIGHT 2))
- (define MTS (empty-scene WIDTH HEIGHT))
- (define CAT-IMG .)
- ;; =================
- ;; Data definitions:
- ;; Cat is Number
- ;; interp. x position of the cat in screen coordinates
- (define C1 0) ;; left edge
- (define C2 (/ WIDTH 2)) ;; middle
- (define C3 WIDTH) ;; right edge
- (define (fn-for-cat c)
- (... c))
- ;; template rules used:
- ;; - simple atomic nondistinct
- ;; =================
- ;; Functions:
- ;; Cat -> Cat
- ;; start the world with ...
- ;;
- (define (main c)
- (big-bang c ; Cat
- (on-tick advance-cat) ; Cat -> Cat
- (to-draw render))) ; Cat -> Image
- ;; Cat -> Cat
- ;; produce a cat that is 1 pixel to the right of the input cat
- (define (advance-cat c)
- (+ c 1))
- (check-expect (advance-cat 3) 4)
- ;; Cat -> Image
- ;; Draw the cat image on the MTS
- (define (render c)
- (place-image CAT-IMG c CAT-Y MTS))
- (check-expect (render 4) (place-image CAT-IMG 4 CAT-Y MTS))
- (main 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement