;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname entry2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp"))))) (start 300 300) (define-struct person (body left right)) ; creates the structure person, with the body and both hands (define-struct ship (ship beam)) ; creates the structure ship, with the ship and beam (define-struct hand (x y)) ; creates hand (define-struct body (x y)) ; creates the body (define (draw-person left right body) ; altering the size of the hands or the bodies would require rewriting of the positioning code. For this reason, these alterations are not supported. size is hardwired. (and (draw-solid-disk (make-posn (+ 15 (body-x body)) (- (body-y body) 15)) 15 'yellow) ; head ; the head does not move, so its position is entirely based on the position of the body (draw-solid-rect (make-posn (body-x body) (body-y body)) 30 70 'red) ; body (draw-solid-disk (make-posn (- (body-x body) (hand-x left)) (+ (body-y body) (hand-y left))) 8 'blue) ; left hand (draw-solid-disk (make-posn (+ (body-x body) (hand-x right) 30) (+ (body-y body) (hand-y right))) 8 'blue) ;right hand ; the left hands and right hands are, for the most part, reversals of eachothers' code. this means the data is distance from center and height, allowing the code to be nearly entirely reused between the hands. that is, a left hand in a given position is the same code as the right hand in the mirrored position. )) (define (clear x) (and (sleep-for-a-while 1)(clear-solid-rect (make-posn x 0) 300 300 'red))) ; makes the clearing of the screen and sleep-for-a-while into a single function, thereby not requiring anything more elaborate within the individual functions (define (space-ship the-ship) (and (draw-solid-rect (make-posn (ship-ship the-ship) 0) 150 40 'gray) (cond [(ship-beam the-ship) (draw-solid-rect (make-posn (+ 40 (ship-ship the-ship)) 40) 20 300'green)] [else true]))); ship (define body1 (make-body 135 215)) ; makes the first body, used in most of the program (define body2 (make-body 135 175)) ; makes the second body, slightly elevated (define body3 (make-body 135 125)) ; makes the third body, more elevated (define hand1 (make-hand 5 35)) ; makes the first hand and second, as they use the same values at first (define hand2 (make-hand 15 10)) ; makes a nearby hand, slightly dropped (define hand3 (make-hand 35 10)) ; makes a far hand, slightly dropped (define hand4 (make-hand -5 -10)) ; makes an elevated hand covering where the "mouth" (define ship1 (make-ship -50 false)) ; makes the first ship, far off w/o the beam (define ship2 (make-ship 0 false)) (define ship3 (make-ship 50 false)) (define ship4 (make-ship 100 true)) ; the beam is turned on (define ship5 (make-ship 100 false)) ; the beam is turned off (define ship6 (make-ship 150 false)) ; the ship goes on its merry way ;; Animation Starts (draw-person hand1 hand1 body1) (clear 0) (space-ship ship1) ; the ship is drawn first to allow the person to overlap the beam (draw-person hand2 hand3 body1) (clear 0) (space-ship ship2) (draw-person hand3 hand2 body1) (clear 0) (space-ship ship3) (draw-person hand2 hand3 body1) (clear 0) (space-ship ship4) (draw-person hand3 hand2 body1) (clear 0) (space-ship ship4) (draw-person hand4 hand4 body2) (clear 0) (space-ship ship4) (draw-person hand4 hand4 body3) (clear 0) (space-ship ship5) (clear 0) (space-ship ship6)