;; The first three lines of this file were inserted by DrRacket. 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 |1301 lab 3|) (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"))))) ;;1301 Lab 3-Creating a Cartoon ;;FACE- this structure deals with the background circle for the face (define-struct face (center rad color)) ;;Contract: face->boolean ;;Purpose: to draw the background circle for the face, given the position of the center, the radius and a color (define (draw-face a-face) (draw-solid-disk (face-center a-face) (face-rad a-face) (face-color a-face))) ;;EYES-this structure deals with the eyes of the face (define-struct eyes (center1 center2 rad color)) ;;draw eyes ;;Contract: eyes->boolean ;;Purpose: to draw the eyes of the face, given the position of the center of each eye, the radius, and a color (define (draw-eyes a-eyes) (and (draw-solid-disk (eyes-center1 a-eyes) (eyes-rad a-eyes) (eyes-color a-eyes)) (draw-solid-disk (eyes-center2 a-eyes) (eyes-rad a-eyes) (eyes-color a-eyes)))) ;;clear eyes ;;Contract: eyes->boolean ;;Purpose: to clear the eyes of the face, given the position of the center of each eye, the radius, and a color. (define (clear-eyes a-eyes) (and (clear-solid-disk (eyes-center1 a-eyes) (eyes-rad a-eyes) (eyes-color a-eyes)) (clear-solid-disk (eyes-center2 a-eyes) (eyes-rad a-eyes) (eyes-color a-eyes)))) ;;CLOSED EYES-this structure deals with making the eyes look like they're closed (define-struct ceyes (ltcorner1 ltcorner2 width height color)) ;;draw closed eyes ;;Contract: ceyes->boolean ;;Purpose: to draw closed eyes, given the position of the left-top corner of each eye, width, height and a color ;;note: we do not have a function to clear the closed eyes because it is unnecessary, the 'open eyes' cover the closed eyes (define (draw-ceyes a-eyes) (and (draw-solid-rect (ceyes-ltcorner1 a-eyes) (ceyes-width a-eyes) (ceyes-height a-eyes) (ceyes-color a-eyes)) (draw-solid-rect (ceyes-ltcorner2 a-eyes) (ceyes-width a-eyes) (ceyes-height a-eyes) (ceyes-color a-eyes)))) ;;EYEBROWS- this structure deals with the eyebrows of the face (define-struct eyebrows (ltcorner1 ltcorner2 width height color)) ;;draw eyebrows ;;Contract: eyebrows->boolean ;;Purpose: to draw the eyebrows of the face, given the position of the left-top corner of each eyebrow, the width, the height, and a color. (define (draw-eyebrows a-eyebrows) (and (draw-solid-rect (eyebrows-ltcorner1 a-eyebrows) (eyebrows-width a-eyebrows) (eyebrows-height a-eyebrows) (eyebrows-color a-eyebrows)) (draw-solid-rect (eyebrows-ltcorner2 a-eyebrows) (eyebrows-width a-eyebrows) (eyebrows-height a-eyebrows) (eyebrows-color a-eyebrows)))) ;;clear eyebrows ;;Contract: eyebrows->boolean ;;Purpose: to clear the eyebrows of the face, given the position of the left-top corner of each eyebrow, the width, the height, and a color. (define (clear-eyebrows a-eyebrows) (and (clear-solid-rect (eyebrows-ltcorner1 a-eyebrows) (eyebrows-width a-eyebrows) (eyebrows-height a-eyebrows) (eyebrows-color a-eyebrows)) (clear-solid-rect (eyebrows-ltcorner2 a-eyebrows) (eyebrows-width a-eyebrows) (eyebrows-height a-eyebrows) (eyebrows-color a-eyebrows)))) ;;MOUTH-this structure deals with the mouth of the face (define-struct mouth (ltcorner width height color)) ;;draw mouth ;;Contract: mouth->boolean ;;Purpose: to draw the mouth of the face given the position of its left-top corner, the width, the height and a color. (define (draw-mouth a-mouth) (draw-solid-rect (mouth-ltcorner a-mouth) (mouth-width a-mouth) (mouth-height a-mouth) (mouth-color a-mouth))) ;;clear mouth ;;Contract: mouth->boolean ;;Purpose: to clear the mouth, given the position of its left-top corner, the width, the height and a color. (define (clear-mouth a-mouth) (clear-solid-rect (mouth-ltcorner a-mouth) (mouth-width a-mouth) (mouth-height a-mouth) (mouth-color a-mouth))) ;;CIRCLE MOUTH-this structure deals with the mouth of the face in the shape of a circle. This is for the surprised face. (define-struct cmouth (center rad color)) ;;draw circle mouth ;;Contract: cmouth->boolean ;;Purpose: to draw the mouth in the shape of a circle, given the position of its center, a radius and a color. (define (draw-cmouth a-mouth) (draw-solid-disk (cmouth-center a-mouth) (cmouth-rad a-mouth) (cmouth-color a-mouth))) ;;Beginning the cartoon (start 550 550) (define face1 (make-face (make-posn 275 275) 250 'yellow)) (define eyes1 (make-eyes (make-posn 185 175) (make-posn 365 175) 30 'black)) (define filleyes1 (make-eyes (make-posn 185 175) (make-posn 365 175) 30 'yellow)) (define eyes2 (make-eyes (make-posn 230 185) (make-posn 310 185) 15 'black)) (define filleyes2 (make-eyes (make-posn 230 185) (make-posn 310 185) 15 'yellow)) (define eyes3 (make-ceyes (make-posn 156 165) (make-posn 336 165) 58 20 'black)) (define eyebrows1 (make-eyebrows (make-posn 155 125) (make-posn 335 125) 60 10 'black)) (define filleyebrows1 (make-eyebrows (make-posn 155 125) (make-posn 335 125) 60 10 'yellow)) (define eyebrows2 (make-eyebrows (make-posn 155 115) (make-posn 335 115) 60 10 'black)) (define filleyebrows2 (make-eyebrows (make-posn 155 115) (make-posn 335 115) 60 10 'yellow)) (define mouth1 (make-mouth (make-posn 140 345) 270 30 'black)) (define fillmouth (make-mouth (make-posn 140 345) 270 30 'yellow)) (define mouth2 (make-cmouth (make-posn 275 375) 120 'black)) ;;face1 (draw-face face1) (draw-eyes eyes1) (draw-eyebrows eyebrows1) (draw-mouth mouth1) (sleep-for-a-while 1) ;;face2: crosseyed (clear-eyes eyes1) (draw-eyes filleyes1) (draw-eyes eyes2) (sleep-for-a-while 1) (clear-eyes eyes2) (draw-eyes filleyes2) (draw-eyes eyes1) (sleep-for-a-while 1) ;;face3: blink (clear-eyes eyes1) (draw-eyes filleyes1) (draw-ceyes eyes3) (sleep-for-a-while .2) (draw-eyes eyes1) (sleep-for-a-while 1) ;;face4: raise eyebrows (clear-eyebrows eyebrows1) (draw-eyebrows filleyebrows1) (draw-eyebrows eyebrows2) (sleep-for-a-while .3) (clear-eyebrows eyebrows2) (draw-eyebrows filleyebrows2) (draw-eyebrows eyebrows1) (sleep-for-a-while .5) (clear-eyebrows eyebrows1) (draw-eyebrows filleyebrows1) (draw-eyebrows eyebrows2) (sleep-for-a-while .3) (clear-eyebrows eyebrows2) (draw-eyebrows filleyebrows2) (draw-eyebrows eyebrows1) (sleep-for-a-while 1) ;;lastface (clear-eyebrows eyebrows1) (draw-eyebrows filleyebrows1) (draw-eyebrows eyebrows2) (clear-mouth mouth1) (draw-mouth fillmouth) (draw-cmouth mouth2) (sleep-for-a-while 1.5) (stop)