;; 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 entry8) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))))) ;Contract symbol -> boolean and a drawing ;Purpose To create a cartoon that provides the illusion of movement of ;pacman (start 300 300) (draw-solid-line (make-posn 0 25) (make-posn 200 25) 'blue) (draw-solid-line (make-posn 0 110) (make-posn 200 110) 'blue) ;these give the background lines for pacman (define-struct pacman (body eye mouthlength mouthwidth)) ;All these structure parts are numbers. body is radius of body, eye is ;radius of the eye, mouthlength is the length of his mouth, and ;mouthwidth is the width of his mouth (define pacman1 (make-pacman 40 5 25 20)) ;this makes our pacman that we use (define-struct dot (radius color)) ;radius is a number for the radius of the dot and the color is a color (define dot1 (make-dot 5 'black)) ;the dots that we use (dot-color dot1) (dot-radius dot1) ;testing the selectors (pacman-body pacman1) ;testing the selectors (define (PacmanMouth Position) (cond [(symbol=? Position 'closed) (and (clear-solid-disk (make-posn 90 72.5) (dot-radius dot1) (dot-color dot1)) (clear-solid-disk (make-posn 170 72.5) (dot-radius dot1) (dot-color dot1)) (draw-solid-disk (make-posn 60 70) (pacman-body pacman1) 'yellow) (draw-solid-disk (make-posn 75 50) (pacman-eye pacman1) 'black) (draw-solid-rect (make-posn 75 72.5) (pacman-mouthlength pacman1) 1 'black) (draw-solid-disk (make-posn 130 72.5) (dot-radius dot1) (dot-color dot1)) )];this whole sequence clears the tow dots created when the mouth is open and ;then draws a third dot in the middle of where they were. It also then draws pacman ;with his mouth closed [(symbol=? Position 'open) (and (clear-solid-disk (make-posn 130 72.5) (dot-radius dot1) (dot-color dot1)) (draw-solid-disk (make-posn 60 70) (pacman-body pacman1) 'yellow) (draw-solid-disk (make-posn 75 50) (pacman-eye pacman1) 'black) (draw-solid-rect (make-posn 80 65) (pacman-mouthlength pacman1) (pacman-mouthwidth pacman1) 'white) (draw-solid-disk (make-posn 90 72.5) (dot-radius dot1) (dot-color dot1)) (draw-solid-disk (make-posn 170 72.5) (dot-radius dot1) (dot-color dot1)) )];this erases the dot created when the mouth is closed and draws pacman with on ;dot in his mouth and one far away [(symbol=? Position 'final1) (and (clear-solid-disk (make-posn 130 72.5) (dot-radius dot1) (dot-color dot1)) (draw-solid-disk (make-posn 60 70) (pacman-body pacman1) 'yellow) (draw-solid-disk (make-posn 75 50) (pacman-eye pacman1) 'black) (draw-solid-rect (make-posn 80 65) (pacman-mouthlength pacman1) (pacman-mouthwidth pacman1) 'white) (draw-solid-disk (make-posn 90 72.5) (dot-radius dot1) (dot-color dot1)) )];needed to complete illusion of movement by not adding another dot [(symbol=? Position 'final2) (and (clear-solid-disk (make-posn 90 72.5) (dot-radius dot1) (dot-color dot1)) (clear-solid-disk (make-posn 170 72.5) (dot-radius dot1) (dot-color dot1)) (draw-solid-disk (make-posn 60 70) (pacman-body pacman1) 'yellow) (draw-solid-disk (make-posn 75 50) (pacman-eye pacman1) 'black) (draw-solid-rect (make-posn 75 72.5) (pacman-mouthlength pacman1) 1 'black) (sleep-for-a-while 1) ;needed to eat last dot without drawing a new one )] ) ) (PacmanMouth 'open) (sleep-for-a-while .25) (PacmanMouth 'closed) (sleep-for-a-while .25) (PacmanMouth 'open) (sleep-for-a-while .25) (PacmanMouth 'closed) (sleep-for-a-while .25) (PacmanMouth 'open) (sleep-for-a-while .25) (PacmanMouth 'closed) (sleep-for-a-while .25) (PacmanMouth 'open) (sleep-for-a-while .25) (PacmanMouth 'closed) (sleep-for-a-while .25) (PacmanMouth 'final1) (sleep-for-a-while .25) (PacmanMouth 'final2) (sleep-for-a-while .25) ;repeated runnings of our code in order to make it seem as though pacman is moving