Advertisement
Guest User

Untitled

a guest
May 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.16 KB | None | 0 0
  1.  
  2.  
  3. (require 2htdp/image)
  4. (require 2htdp/universe)
  5.  
  6. ;; A cat that walks from right to left
  7.  
  8. ;; =================
  9. ;; Constants:
  10.  
  11. (define WIDTH 600)
  12. (define HEIGHT 400)
  13. (define CAT-Y (/ HEIGHT 2))
  14. (define MTS (empty-scene WIDTH HEIGHT))
  15. (define CAT-IMG .)
  16.  
  17.  
  18. ;; =================
  19. ;; Data definitions:
  20.  
  21. ;; Cat is Number
  22. ;; interp. x position of the cat in screen coordinates
  23. (define C1 0) ;; left edge
  24. (define C2 (/ WIDTH 2)) ;; middle
  25. (define C3 WIDTH) ;; right edge
  26.  
  27. (define (fn-for-cat c)
  28.   (... c))
  29.  
  30. ;; template rules used:
  31. ;; - simple atomic nondistinct
  32.  
  33.  
  34.  
  35. ;; =================
  36. ;; Functions:
  37.  
  38. ;; Cat -> Cat
  39. ;; start the world with ...
  40. ;;
  41. (define (main c)
  42.   (big-bang c                        ; Cat
  43.             (on-tick   advance-cat)  ; Cat -> Cat
  44.             (to-draw   render)))     ; Cat -> Image
  45.  
  46. ;; Cat -> Cat
  47. ;; produce a cat that is 1 pixel to the right of the input cat
  48. (define (advance-cat c)
  49.   (+ c 1))
  50.  
  51. (check-expect (advance-cat 3) 4)
  52.  
  53.  
  54. ;; Cat -> Image
  55. ;; Draw the cat image on the MTS
  56.  
  57. (define (render c)
  58.   (place-image CAT-IMG c CAT-Y MTS))
  59.  
  60. (check-expect (render 4) (place-image CAT-IMG 4 CAT-Y MTS))
  61.  
  62. (main 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement