Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; A Circle is:
- ; (make-Circle posn number color)
- (define-struct Circle (center radius clr))
- (define C1 (make-Circle (make-posn 0 0) 5 "purple"))
- (define C2 (make-Circle (make-posn 2 4) 12 "blue"))
- ; ;; Circle-fun: Circle ->
- ; ;; given ..., produces
- ; (define (Circle-fun a-Circle)
- ; (Circle-center a-Circle)
- ; (Circle-radius a-Circle)
- ; (Circle-clr a-Circle))
- ;
- ; (check-expect (Circle-fun ...) ...)
- ; (check-expect (Circle-fun ...) ...)
- ;
- ;
- ; ;; 3.
- ;
- ; ;; Circle-circumference: Circle -> number
- ; ;; given a Circle, produces its circumference
- ; (define (Circle-circumference a-Circle)
- ; (* 3.14 (expt (Circle-center a-Circle) 2)))
- ;
- ;
- ; (check-expect (Circle-circumference C1) )
- ; (check-expect (Circle-circumference C2) ...)
- ; ; 1.
- ;
- ; ; Circle-fun: Circle -> ?
- ;
- ; ; given ..., produces ...
- ;
- ; (define (Circle-fun a-Circle)
- ;
- ; (Circle-center a-Circle)
- ;
- ; (Circle-radius a-Circle)
- ;
- ; (Circle-clr a-Circle))
- ;
- ; 3.
- ; Circle-circumference: Circle -> number
- ; given a Circle, produces its cirumference
- (define (circumference a-Circle)
- (* 3.14 (* 2 Circle-radius a-Circle)))
- (check-expect (Circle-circumference C1) 31.4)
- (check-expect (Circle-circumference C2) 56.52)
- ; 4.
- ; Circle-area: Circle -> number
- ; given a Circle, produces its area
- (define (Circle-area a-Circle)
- (* 3.14 (sqr Circle-radius a-Circle)))
- (check-expect (Circle-area C1) 78.5)
- (check-expect (Circle-area C2) 153.86)
- ; 5.
- ; Circle=?: Circle Circle -> boolean
- ; given two Circles, produces whether they're the same
- (define (Circle=? a-Circle b-Circle)
- (and (posn=? (Circle-center a-Circle) (Circle-Center b-Circle))
- (= (Circle-radius a-Circle) (Circle-radius b-Circle))
- (string=? (Circle-clr a-Circle) (Circle-clr b-Circle))))
- (check-expect (Circle=? S1 S2) false)
- (check-expect (Circle=? S1 (make-Circle (make-posn 25 25) 5 "silver"))
- true)
- ; 6.
- ; draw-Circle: Circle -> image
- ; given a Circle, produces an image of a Circle of the correct size and
- ; color
- (define (draw-Circle a-Circle)
- (circle (Circle-center a-Circle)
- (Circle-radius a-Circle)
- "outline"
- (Circle-clr a-Circle)))
- (check-expect (draw-Circle C1) (circle (make-posn 25 25) 5 "outline" "purple"))
- (check-expect (draw-Circle C2) (circle (make-posn 7 7) 9 "outline" "green"))
- ; 7.
- ; place-Circle: Circle image -> image
- ; given a Circle and an image, produces a new image with the Circle
- ; placed in the right location on it
- ; (define (place-Circle a-Circle bg)
- ; (place-image/align (draw-Circle a-Circle)
- ; (posn-x (Circle-center a-Circle))
- ; (posn-y (Circle-Center a-Circle))
- ; "left" "top"
- ; bg))
- ;
- ;
- ;
- ; (check-expect (place-Circle C1 (empty-scene 100 100))
- ; (place-image/align (circle (make-posn 25 25) 5 "blue")
- ; "left" "top")
- ; (empty-scene 100 100))
- ; (check-expect (place-Square C2 (rectangle 200 300 "solid" "black"))
- ; (place-image/align (circle (make-posn 7 7) 9 "silver")
- ; "left" "top")
- ; (rectangle 200 300 "solid" "black"))
- ;8.
- ; Circle-translate: Circle number number -> Circle
- ; given a Circle and a number of pixels to move it down and over,
- ; produces a new Circle at that location
- (define (Circle-translate a-Circle delta-x delta-y)
- (make-Circle (posn-translate (Circle-center a-Circle)
- delta-x
- delta-y)
- (Circle-radius a-Circle)
- (Circle-clr a-Circle)))
- (check-expect (Circle-translate C1 25 25)
- (make-Circle (make-posn 50 50) 10 "blue"))
- (check-expect (Circle-translate C2 7 7)
- (make-Circle (make-posn 14 14) 16 "silver"))
Add Comment
Please, Sign In to add comment