;; 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 entry5_not_contest) (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"))))) ;;Contract: numbers(b) -> boolean/pictures ;;Purpose: "write a program for a simple cartoon that moves a picture constructed of geometric shapes" (start 300 300) ;;;;;;;;;;;;;;;;;CIRCLE;;;;;;;;;;;;;;;;;;;;;;;; (define-struct circle (x y r color)) ;;x,y = center of circle ;;r = radius of circle ;;color = color of circle ;; Draw a Circle (define (draw-a-circle a-circle) (draw-circle (make-posn (circle-x a-circle) (circle-y a-circle)) (circle-r a-circle) (circle-color a-circle) )) ;; Clear a Circle (define (clear-a-circle a-circle) (clear-circle (make-posn (circle-x a-circle) (circle-y a-circle)) (circle-r a-circle) (circle-color a-circle) )) ;; Translate Circle ;;delta = change in x-value (define (translate-circle delta a-circle) (draw-circle (make-posn (+ delta (circle-x a-circle)) (circle-y a-circle)) (circle-r a-circle) (circle-color a-circle) ) ) ;; Move Circle ;;combines draw, clear and translate into one function (define (move-circle a-circle) (and (draw-a-circle a-circle) (sleep-for-a-while 2) (clear-a-circle a-circle) (translate-circle 50 a-circle) ) ) ;;;;;;;;;;;;;;;;;;;RECTANGLE;;;;;;;;;;;;;;;;;;;;;; (define-struct rect (x y h w color)) ;;x,y = position of upper-left hand corner of rectangle ;;h,w = height and width of rectangle ;;color = color of rectangle ;; Draw a Rectangle (define (draw-a-rect a-rect) (draw-solid-rect (make-posn (rect-x a-rect) (rect-y a-rect)) (rect-h a-rect) (rect-w a-rect) (rect-color a-rect))) ;; Clear a Rectangle (define (clear-a-rect a-rect) (clear-solid-rect (make-posn (rect-x a-rect) (rect-y a-rect)) (rect-h a-rect) (rect-w a-rect) (rect-color a-rect))) ;; Translate Rectangle ;;delta = change in x-value ;;alpha = change in y-value (define (translate-rect delta alpha a-rect) (draw-solid-rect(make-posn (+ delta (rect-x a-rect)) (+ alpha (rect-y a-rect))) (rect-h a-rect) (rect-w a-rect) (rect-color a-rect))) ;; Move Rectangle ;;combines draw, clear, and translate into one function (define (move-rect a-rect) (and (draw-a-rect a-rect) (sleep-for-a-while 4) (clear-a-rect a-rect) (translate-rect 50 200 a-rect))) ;;animation of rectangle already included in this function ;;;;;;;;;;;;;;;;;;TRIANGLE;;;;;;;;;;;;;;;;;;;;;;; (define-struct tri (a b x y f g color)) ;;a,b and x,y are endpoints of one line ;;x,y and f,g are endpoints of one line ;;f,g and a,b are endpoints of one line ;;when combined, there are three lines meeting at three points, thus a triangle ;; Draw a Triangle (define (draw-tri a-tri) (and (draw-solid-line (make-posn (tri-x a-tri) (tri-y a-tri)) (make-posn (tri-f a-tri) (tri-g a-tri)) (tri-color a-tri)) (draw-solid-line (make-posn (tri-f a-tri) (tri-g a-tri)) (make-posn (tri-a a-tri) (tri-b a-tri)) (tri-color a-tri)) (draw-solid-line (make-posn (tri-a a-tri) (tri-b a-tri)) (make-posn (tri-x a-tri) (tri-y a-tri)) (tri-color a-tri)))) ;; Clear a Triangle (define (clear-tri a-tri) (and (clear-solid-line (make-posn (tri-x a-tri) (tri-y a-tri)) (make-posn (tri-f a-tri) (tri-g a-tri)) (tri-color a-tri)) (clear-solid-line (make-posn (tri-f a-tri) (tri-g a-tri)) (make-posn (tri-a a-tri) (tri-b a-tri)) (tri-color a-tri)) (clear-solid-line (make-posn (tri-a a-tri) (tri-b a-tri)) (make-posn (tri-x a-tri) (tri-y a-tri)) (tri-color a-tri)))) ;; NOTES: ;;Because of the complexity of the shape and the movement we want, we did not combine draw and clear into a single function ;;instead, for the animation, we just wrote out every movement and clearing we wanted ;;Also, because our black background is actually just a large black rectangle, shapes would leave a large white space after moving ;;to compensate for this, we redrew a black rectangle and a circle to fill in the empty space ;;These two shapes surpass the 10 shape limit but we don't believe these two should be counted as actual shapes as they are being used to fix the picture and are not visible ;;The triangles turning from green to white is intentional (we think it looks cool) ;;;;;;;;;;;;;;;;;TESTS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;All expected values are "true" ;;;;;;;;;;;;;;;;;ANIMATION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Rectangle (draw-a-rect (make-rect 0 0 300 300 'black)) (move-rect (make-rect 40 10 200 100 'blue)) (draw-a-rect (make-rect 40 10 200 100 'black)) (sleep-for-a-while .5) ;;Circle (move-circle (make-circle 50 50 30 'red)) (draw-a-circle (make-circle 50 50 30 'black)) ;;Triangle(s) (define tri1(make-tri 50 50 70 70 60 100 'green)) (draw-tri tri1) (sleep-for-a-while .5) (define tri2 (make-tri 60 60 80 80 70 110 'green)) (draw-tri tri2) (sleep-for-a-while .5) (define tri3 (make-tri 70 70 90 90 80 120 'green)) (draw-tri tri3) (sleep-for-a-while .5) (define tri4 (make-tri 80 80 100 100 90 130 'green)) (draw-tri tri4) (sleep-for-a-while .5) (define tri5 (make-tri 90 90 110 110 100 140 'green)) (draw-tri tri5) (sleep-for-a-while .5) (define tri6 (make-tri 100 100 120 120 110 150 'green)) (draw-tri tri6) (sleep-for-a-while .5) (define tri7 (make-tri 110 110 130 130 120 160 'green)) (draw-tri tri7) (sleep-for-a-while .5) (clear-tri tri1) (sleep-for-a-while .5) (clear-tri tri2) (sleep-for-a-while .5) (clear-tri tri3) (sleep-for-a-while .5) (clear-tri tri4) (sleep-for-a-while .5) (clear-tri tri5) (sleep-for-a-while .5) (clear-tri tri6) (sleep-for-a-while .5) (clear-tri tri7)