PasteRack.org
Paste # 3846
2018-02-16 09:19:21

Fork as a new paste.

Paste viewed 139 times.


Embed:

  1. #lang racket
  2.  
  3. (require 2htdp/image)
  4. (require 2htdp/universe)
  5.  
  6. (define WIDTH 600)
  7. (define HEIGHT (* WIDTH (/ 2 3)))
  8. (define TEXT-SIZE 20)
  9. (define CTR-Y (/ HEIGHT 2))
  10.  
  11. (define MTS (empty-scene WIDTH HEIGHT))
  12.  
  13. (define CAT-IMG (rectangle 40 60 "solid" "brown"))
  14.  
  15. ;; ============================
  16. ;; Data definitions:
  17.  
  18. ;; Cat is Number
  19. ;; interp. x position of the cat in screen coordinates
  20.  
  21. (define C1 0)
  22. (define C2 (/ WIDTH 2))
  23. (define C3 WIDTH)
  24.  
  25. ;; Template rules used:
  26. ;;  - atomic non-distinct: Number
  27.  
  28. ;; ============================
  29. ;; Functions:
  30.  
  31. ;; Cat -> Cat
  32. ;; start the world with ...
  33.  
  34. (define (main c)
  35.   (big-bang c
  36.             (on-tick advance-cat)
  37.             (to-draw render)))
  38.  
  39. ;; Cat -> Cat
  40. ;; produce the next cat by advancing it 1 pixel to the right
  41. ;; !!!
  42. (define (advance-cat c)
  43.   (+ c 5))
  44.  
  45.  
  46. ;; Cat -> Image
  47. ;; render the cat image at appropriate place on MTS
  48. ;; !!!
  49. (define (render c)
  50.   (place-image CAT-IMG c CTR-Y MTS))
  51.  
  52. (main CAT-IMG)

=>