;; 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 entry10) (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 3 (Cartoon Lab) (start 700 500) ;;defines the cannonball structure as having a center, radius, and color (define-struct cannonball (center radius color)) ;;Contract: structure -> boolean ;;draws the cannonball structure as being a solid disk (define (draw-cannonball a-cannonball) (draw-solid-disk (cannonball-center a-cannonball) (cannonball-radius a-cannonball) (cannonball-color a-cannonball))) ;;defines a-posn as falling on the point (350, 250) (define a-posn (make-posn 350 250)) ;;defines the structure cannonball1 as having a center at a-posn, a radius of 50, and the color black (define cannonball1 (make-cannonball a-posn 50 'black)) ;;Contract: structure -> boolean ;;Purpose: clears the given cannonball structure (define (clear-cannonball a-cannonball) (clear-solid-disk (cannonball-center a-cannonball) (cannonball-radius a-cannonball))) ;;Contract: structure number -> boolean ;;Purpose: draws another cannonball with a center a certain distance (delta) away from that of the original cannonball (define (translate-cannonball a-cannonball delta) (draw-solid-disk (make-posn (+ (posn-x a-posn) delta) (posn-y a-posn)) (cannonball-radius a-cannonball) (cannonball-color a-cannonball) ) ) ;;Contract: structure -> boolean ;;Purpose: draws the cannonball structure, waits 0.1 seconds, then clears it (define (draw-and-clear-cannonball a-cannonball) (and [draw-cannonball a-cannonball] [sleep-for-a-while .1] [clear-cannonball a-cannonball])) ;;Contract: number structure -> boolean ;;Purpose: moves the cannonball structure a certain so that its center is a distance of (delta) away from that of the original (define (move-cannonball delta a-cannonball) (cond [(translate-cannonball a-cannonball delta)(draw-and-clear-cannonball a-cannonball)] [else a-cannonball])) (draw-solid-rect (make-posn 0 0) 700 500 'lightblue) (draw-solid-rect (make-posn 0 350) 200 150 'brown) (draw-solid-rect (make-posn 200 300) 100 300 'gray) (draw-solid-rect (make-posn 100 200) 300 100 'black) (draw-solid-rect (make-posn 40 245) 20 10 'black) (draw-solid-disk (make-posn 100 250) 50 'black) (draw-solid-rect (make-posn 400 180) 25 140 'black) (sleep-for-a-while 2) (draw-cannonball cannonball1) (move-cannonball 150 cannonball1) (draw-solid-disk (make-posn 500 250) 50 'lightblue) (move-cannonball 300 cannonball1) (draw-solid-disk (make-posn 650 250) 50 'lightblue) (draw-solid-rect (make-posn 100 200) 300 100 'black) (sleep-for-a-while .5) (clear-all) ;;------------------------SCENE-2---------------------------------------------------------- ;;defines a ship structure as containing the following values: ;;hullcorner, hulllength, hullheight, hullcolor, polecorner, ;;polelength, poleheight, polecolor, mast1corner, mast1length, mast1height, ;;mast1color, mast2corner, mast2length, mast2height, mast2color (define-struct ship (hullcorner hulllength hullheight hullcolor polecorner polelength poleheight polecolor mast1corner mast1length mast1height mast1color mast2corner mast2length mast2height mast2color)) ;;Contract: posn number number symbol ;;posn number number symbol ;;posn number number symbol ;;posn number number symbol ;;Purpose: draws the ship structure (define (draw-ship a-ship) (and (draw-solid-rect (ship-hullcorner a-ship) (ship-hulllength a-ship) (ship-hullheight a-ship) (ship-hullcolor a-ship)) (draw-solid-rect (ship-polecorner a-ship) (ship-polelength a-ship) (ship-poleheight a-ship) (ship-polecolor a-ship)) (draw-solid-rect (ship-mast1corner a-ship) (ship-mast1length a-ship) (ship-mast1height a-ship) (ship-mast1color a-ship)) (draw-solid-rect (ship-mast2corner a-ship) (ship-mast2length a-ship) (ship-mast2height a-ship) (ship-mast2color a-ship)) ) ) ;;defines the values of the ship1 structure (define ship1 (make-ship (make-posn 275 340) 150 10 'brown (make-posn 348 240) 4 100 'brown (make-posn 318 250) 64 30 'white (make-posn 308 288) 84 40 'white)) ;;defines b-posn as being on the point (20 280) (define b-posn (make-posn 20 280)) ;;defines the cannonball2 structure as having a center at b-posn, radius of 15, and the color black (define cannonball2 (make-cannonball b-posn 15 'black)) ;;Contract: structure number number -> boolean ;;Purpose: draws another cannonball structure a distance of delta1 to the right and delta2 down from the input (define (translatediag-cannonball a-cannonball delta1 delta2) (draw-solid-disk (make-posn (+ (posn-x b-posn) delta1) (+ (posn-y b-posn) delta2)) (cannonball-radius a-cannonball) (cannonball-color a-cannonball) ) ) ;;Contract: number number structure -> boolean ;;Purpose: to move the cannonball structure a given distance to the right and down while erasing the pervious one (define (move-cannonballdiag delta1 delta2 a-cannonball) (cond [(translatediag-cannonball a-cannonball delta1 delta2)(draw-and-clear-cannonball a-cannonball)] [else a-cannonball] ) ) (draw-solid-rect (make-posn 0 0) 700 500 'lightblue) (draw-solid-rect (make-posn 0 350) 700 150 'blue) (draw-ship ship1) (sleep-for-a-while 1) (draw-cannonball cannonball2) (move-cannonballdiag 100 10 cannonball2) (draw-solid-disk b-posn 15 'lightblue) (move-cannonballdiag 200 20 cannonball2) (draw-solid-disk (make-posn 20 280) 15 'lightblue) (draw-solid-disk (make-posn 120 290) 15 'lightblue) (define (explosion size) (and [draw-solid-disk (make-posn 350 350) size 'blue] [sleep-for-a-while .15] [draw-solid-rect (make-posn 0 0) 700 500 'lightblue] [draw-solid-rect (make-posn 0 350) 700 150 'blue] ) ) (explosion 50) (explosion 100) (explosion 150) (explosion 100) (explosion 50)