;; 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 entry7) (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 200 100) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;the structure set up so we only have to enter one set of values. (define-struct face (posn-x posn-y radius)) ;defines the position of the face. (define h/s (make-face 55 50 30)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;pulls the vaules from the structure and makes the happy face. (define (happy-face x) (and (draw-solid-disk (make-posn (face-posn-x h/s) (face-posn-y h/s)) (face-radius h/s) 'yellow) ;;;;;;;;;;;;;right eye;;;;;;;;;;;;; (draw-solid-disk (make-posn (- (face-posn-x h/s) (/ (face-radius h/s) 10)) (- (face-posn-y h/s) (/ (face-radius h/s) 10))) (/ (face-radius h/s) 10) 'black) ;;;;;;;;;;;;;left eye;;;;;;;;;;;;;; (draw-solid-disk (make-posn (+ (face-posn-x h/s) (/ (face-radius h/s) 10)) (- (face-posn-y h/s) (/ (face-radius h/s) 10))) (/ (face-radius h/s) 10) 'black) ;;;;;;;;;;;;;mouth;;;;;;;;;;;;;;;;; (draw-solid-line (make-posn (face-posn-x h/s) (+ (face-posn-y h/s) (* (face-radius h/s) 0.75))) (make-posn (- (face-posn-x h/s) (/ (face-radius h/s) 2)) (+ (face-posn-y h/s) (/ (face-radius h/s) 2)))) ; (draw-solid-line (make-posn (face-posn-x h/s) (+ (face-posn-y h/s) (* (face-radius h/s) 0.75))) (make-posn (+ (face-posn-x h/s) (/ (face-radius h/s) 2)) (+ (face-posn-y h/s) (/ (face-radius h/s) 2)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;draws a sad face. (define (sad-face x) (and (draw-solid-disk (make-posn (face-posn-x h/s) (face-posn-y h/s)) (face-radius h/s) 'yellow) ;;;;;;;;;;;;;;;;right eye;;;;;;;;;;;; (draw-solid-disk (make-posn (- (face-posn-x h/s) (/ (face-radius h/s) 10)) (- (face-posn-y h/s) (/ (face-radius h/s) 10))) (/ (face-radius h/s) 10) 'black) ;;;;;;;;;;;;;;;;left eye;;;;;;;;;;;;; (draw-solid-disk (make-posn (+ (face-posn-x h/s) (/ (face-radius h/s) 10)) (- (face-posn-y h/s) (/ (face-radius h/s) 10))) (/ (face-radius h/s) 10) 'black) ;;;;;;;;;;;;;;;;mouth;;;;;;;;;;;;;;;; (draw-solid-line (make-posn (face-posn-x h/s) (+ (face-posn-y h/s) (/ (face-radius h/s) 3))) (make-posn (- (face-posn-x h/s) (/ (face-radius h/s) 2)) (+ (face-posn-y h/s) (/ (face-radius h/s) 2)))) ; (draw-solid-line (make-posn (face-posn-x h/s) (+ (face-posn-y h/s) (/ (face-radius h/s) 3))) (make-posn (+ (face-posn-x h/s) (/ (face-radius h/s) 2)) (+ (face-posn-y h/s) (/ (face-radius h/s) 2)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;clears the face (define (clear-face x) (clear-solid-disk (make-posn (face-posn-x h/s) (face-posn-y h/s)) (face-radius h/s))) ;defines the structure ball (define-struct ball (posn-x posn-y rad color)) ;defines the dodge ball (define d-ball (make-ball 210 50 15 'red)) ;moves the ball x spaces to the left (define (move-ball x) (and (clear-solid-disk (make-posn (- (ball-posn-x d-ball) (- x 20)) (ball-posn-y d-ball)) (ball-rad d-ball)) (draw-solid-disk (make-posn (- (ball-posn-x d-ball) x) (ball-posn-y d-ball))(ball-rad d-ball)(ball-color d-ball)))) (happy-face true) (sleep-for-a-while 1) (move-ball 20) (sleep-for-a-while 1) (move-ball 40) (sleep-for-a-while 1) (move-ball 60) (sleep-for-a-while 1) (move-ball 80) (sleep-for-a-while 1) (move-ball 100) (sleep-for-a-while 1) (move-ball 120) (sleep-for-a-while 1) (move-ball 140) (sleep-for-a-while 1) (clear-face true) (sad-face true) (sleep-for-a-while 1)