;; 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 entry11) (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"))))) ;; Lab 4 ;; dimensions of our comic (define WIDTH 500) (define HEIGHT 300) (define (draw-person x y) ; this function draws our person (and (draw-circle (make-posn x y) 20 'purple) ; head (draw-solid-line (make-posn x (+ y 20)) (make-posn x (+ y 70)) 'purple) ;body (draw-solid-line (make-posn (- x 20) (+ y 35)) (make-posn (+ x 20) (+ y 35)) 'purple) ; arms (draw-solid-line (make-posn x (+ y 70)) (make-posn (- x 15) (+ y 90)) 'purple) ; left leg (draw-solid-line (make-posn x (+ y 70)) (make-posn (+ x 15) (+ y 90)) 'purple) ; right leg ) ) (define (clear-person x y) ; this function clears our person (and (clear-circle (make-posn x y) 20 'purple) (clear-solid-line (make-posn x (+ y 20)) (make-posn x (+ y 70)) 'purple) (clear-solid-line (make-posn (- x 20) (+ y 35)) (make-posn (+ x 20) (+ y 35)) 'purple) (clear-solid-line (make-posn x (+ y 70)) (make-posn (- x 15) (+ y 90)) 'purple) (clear-solid-line (make-posn x (+ y 70)) (make-posn (+ x 15) (+ y 90)) 'purple))) (define (move-person oldx oldy newx newy) ; we can use this to move our person from one point to another (and (clear-person oldx oldy) (draw-person newx newy))) ;; Data Definition: center, line1a, line1b, line2a, line2b are all posn) (define-struct ball (center line1a line1b line2a line2b)) (define (new-hball center) ; this function creates our basketball, with horizontal stripes (make-ball center (make-posn (- (posn-x center) 14) (- (posn-y center) 2)) (make-posn (+ (posn-x center) 14) (- (posn-y center) 2)) (make-posn (- (posn-x center) 14) (+ (posn-y center) 2)) (make-posn (+ (posn-x center) 14) (+ (posn-y center) 2))) ) (define (new-vball center) ; this will define a ball structure with vertical stripes, so that it looks like our ball is rotating (make-ball center (make-posn (- (posn-x center) 2) (- (posn-y center) 14)) (make-posn (- (posn-x center) 2) (+ (posn-y center) 14)) (make-posn (+ (posn-x center) 2) (- (posn-y center) 14)) (make-posn (+ (posn-x center) 2) (+ (posn-y center) 14))) ) (define (draw-ball ballname) ; this uses the ball structures above to actually show the ball (and (draw-solid-disk (ball-center ballname) 15 'orange) (draw-solid-line (ball-line1a ballname) (ball-line1b ballname) 'black) (draw-solid-line (ball-line2a ballname) (ball-line2b ballname) 'black) ) ) (define (clear-ball ballname) ; this clears our ball off the screen, so we can move the position (and (clear-solid-disk (ball-center ballname) 15 'orange) (clear-solid-line (ball-line1a ballname) (ball-line1b ballname) 'black) (clear-solid-line (ball-line2a ballname) (ball-line2b ballname) 'black) ) ) (define (move-ball ball1 ball2) ; first, this function clears our original ball, then it creates a new one in a different position. (and (clear-ball ball1) (draw-ball ball2) ) ) ; Here is our actual animation. It is a slide show of a person shooting a ball into a hoop. (start WIDTH HEIGHT) (and (draw-solid-rect (make-posn 480 50) 15 250 'gray) ; stand (draw-circle (make-posn 460 100) 20 'red) ; hoop ) ;these two objects together form our basketball hoop (and (draw-person 50 200) (draw-ball (new-hball (make-posn 70 250)))) (sleep-for-a-while .5) (and (move-ball (new-hball (make-posn 70 250)) (new-vball (make-posn 105 275))) (move-person 50 200 75 200)) (sleep-for-a-while .5) (and (move-ball (new-vball (make-posn 105 275)) (new-hball (make-posn 120 250))) (move-person 75 200 100 200)) (sleep-for-a-while .5) (and (move-ball (new-hball (make-posn 120 250)) (new-vball (make-posn 155 275))) (move-person 100 200 125 200)) (sleep-for-a-while .5) (and (move-ball (new-vball (make-posn 155 275)) (new-hball (make-posn 170 250))) (move-person 125 200 150 200)) (sleep-for-a-while .5) (and (move-ball (new-hball (make-posn 170 250)) (new-vball (make-posn 195 180))) (move-person 150 200 160 150)) (sleep-for-a-while .5) (and (move-ball (new-vball (make-posn 195 180)) (new-hball (make-posn 220 140))) (move-person 160 150 175 165)) (sleep-for-a-while .75) ;Note, we started adding in extra sleep time for dramatic effect!!! (and (move-ball (new-hball (make-posn 220 140)) (new-vball (make-posn 270 90))) (move-person 175 165 190 200)) (sleep-for-a-while 1) (move-ball (new-vball (make-posn 270 90)) (new-hball (make-posn 340 60))) (sleep-for-a-while 1.25) (move-ball (new-hball (make-posn 340 60)) (new-vball (make-posn 460 100))) (sleep-for-a-while .75) (move-ball (new-vball (make-posn 460 100)) (new-hball (make-posn 420 200)))