;; ;; quiz 4 code ;; ;; Here are the structure definitions for the animation entities supported by draw-anim-entity ;; circle : ;; center is a posn ;; radius is a number ;; color is a symbol. 'Clear mean clear the circle! (define-struct circle (center radius color)) ;; square : ;; center is a posn (NOTE we use center, not topleft!) ;; radius is a number ;; color is a symbol. 'Clear means clear the circle (define-struct square (center size color)) ;; delay is just a time in seconds (define-struct delay (time)) ;; draw-anim-entity consumes an animation-entity (a struct that is either ;; a circle, square or delay ;; ;; For square and circle, either draws or clears the entity (based on the color) ;; For delay, just waits for a while ; (define (draw-anim-entity s) (cond [(circle? s) ;; it's a circle - should we draw or clear? (cond [ (symbol=? (circle-color s) 'Clear) ;; clear it (clear-circle (circle-center s) (circle-radius s))] [ else ;; draw it (draw-circle (circle-center s) (circle-radius s) (circle-color s)) ])] [(square? s) ;; it's a square - should we draw or clear? (cond [(symbol=? (square-color s) 'Clear) ;; clear it - need to translate from center to topleft (clear-solid-rect (make-posn (- (posn-x (square-center s)) (/ (square-size s) 2)) (- (posn-y (square-center s)) (/ (square-size s) 2))) (square-size s) (square-size s))] [ else ;; draw it (draw-solid-rect (make-posn (- (posn-x (square-center s)) (/ (square-size s) 2)) (- (posn-y (square-center s)) (/ (square-size s) 2))) (square-size s) (square-size s) (square-color s))])] [(delay? s) ;; it's a delay - wait for a while (sleep-for-a-while (delay-time s))] ;; it's not anything we understand - report an error [else (error 'draw-anim-entity "I dont' know how to draw that (is it an animimation entity?)")])) ;; ;; ;; (start 400 400) ;;(draw-anim-entity ;; (make-square (make-posn 200 200) 141 'Blue)) ;;(draw-anim-entity ;; (make-circle (make-posn 200 200) 100 'Red))