Guest User

Untitled

a guest
Dec 10th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;//Problem 3
  2. ;//vector
  3. ;// constructor (make-vector x y)
  4. ;//Params - x = change in x : y= change in y
  5. (define-struct vector (cx cy))
  6. ;//selectors:
  7. ;//vector-cx - change in x
  8. ;//vector-cy - change in y
  9. ;//pred: vector? any -> true if type is vector
  10. ;------------------------------------------------;
  11. ;//plane our "world"
  12. ;// constructor (make-plane image posn vector)
  13. ;//Params - image, the plane image posn the plane position, and vector the change the direction
  14. (define-struct plane (image posn vector))
  15. ;//selectors:
  16. ;//plane-image - planes image
  17. ;//plane-posn - planes position
  18. ;//plane-vector - planes direction
  19. ;//Pred: plane? any - true if plane
  20. (define (move-plane plane) (make-plane (plane-image plane)
  21. (make-posn (+ (plane-posn-X plane) (plane-vector-cx)) (+ (plane-posn-Y plane) (plane-vector-cy))) (plane-vector plane)))
  22. (define plane1 . )
  23.  
  24. ;;Our scene to render on
  25. (define SCENE (empty-scene 600 600) )
  26. ;;Renders Earth in relation to the sun by angle SW)
  27. (define (render-solar SW)
  28.               (place-image plane1 300 300 SCENE ))
  29. ;(render-solar 0)
  30. ;//Problem 6b,c,d
  31. ;;Will handle a keypress if it is left or right otherwise, does nothing
  32. (define (handle-key SW a-key)
  33.  (cond
  34.    [(key=? a-key "left")  (+ .1 SW)]
  35.    [(key=? a-key "right") (- SW .2)]
  36.    [else SW]))
  37. (check-expect (handle-key 0 "left") .1)
  38. (check-expect (handle-key 0 "right") -.2)
  39. (check-expect (handle-key 0 "up") 0)
  40. ;;Handles a tick, will increase SW by .02
  41. (define (handle-tick SW) (+ SW .02))
  42. (check-expect (handle-tick 0) .02)
  43. ;;Handles MouseClick - Replaces earth at angle 0
  44. (define (handle-mouse SW x y event)
  45.  (if (mouse=? event "button-down") (- SW SW) SW))
  46. (check-expect (handle-mouse 230 100 100 "button-down") 0)
  47. ;;Main function - runs World simulation will all events
  48. (define (main initial-world)
  49. (big-bang
  50. initial-world
  51. (to-draw render-solar)
  52. (on-tick move-plane)
  53. (on-mouse handle-mouse)
  54. (on-key handle-key)))
  55. ;;Test
  56. (main 0)
Add Comment
Please, Sign In to add comment