Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;//Problem 3
- ;//vector
- ;// constructor (make-vector x y)
- ;//Params - x = change in x : y= change in y
- (define-struct vector (cx cy))
- ;//selectors:
- ;//vector-cx - change in x
- ;//vector-cy - change in y
- ;//pred: vector? any -> true if type is vector
- ;------------------------------------------------;
- ;//plane our "world"
- ;// constructor (make-plane image posn vector)
- ;//Params - image, the plane image posn the plane position, and vector the change the direction
- (define-struct plane (image posn vector))
- ;//selectors:
- ;//plane-image - planes image
- ;//plane-posn - planes position
- ;//plane-vector - planes direction
- ;//Pred: plane? any - true if plane
- (define (move-plane plane) (make-plane (plane-image plane)
- (make-posn (+ (plane-posn-X plane) (plane-vector-cx)) (+ (plane-posn-Y plane) (plane-vector-cy))) (plane-vector plane)))
- (define plane1 . )
- ;;Our scene to render on
- (define SCENE (empty-scene 600 600) )
- ;;Renders Earth in relation to the sun by angle SW)
- (define (render-solar SW)
- (place-image plane1 300 300 SCENE ))
- ;(render-solar 0)
- ;//Problem 6b,c,d
- ;;Will handle a keypress if it is left or right otherwise, does nothing
- (define (handle-key SW a-key)
- (cond
- [(key=? a-key "left") (+ .1 SW)]
- [(key=? a-key "right") (- SW .2)]
- [else SW]))
- (check-expect (handle-key 0 "left") .1)
- (check-expect (handle-key 0 "right") -.2)
- (check-expect (handle-key 0 "up") 0)
- ;;Handles a tick, will increase SW by .02
- (define (handle-tick SW) (+ SW .02))
- (check-expect (handle-tick 0) .02)
- ;;Handles MouseClick - Replaces earth at angle 0
- (define (handle-mouse SW x y event)
- (if (mouse=? event "button-down") (- SW SW) SW))
- (check-expect (handle-mouse 230 100 100 "button-down") 0)
- ;;Main function - runs World simulation will all events
- (define (main initial-world)
- (big-bang
- initial-world
- (to-draw render-solar)
- (on-tick move-plane)
- (on-mouse handle-mouse)
- (on-key handle-key)))
- ;;Test
- (main 0)
Add Comment
Please, Sign In to add comment