Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Olivier Gabison
- (require 2htdp/image)
- (require "./iterated-images.rkt")
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Question 1: Using iterated-overlay
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;Part (a): using overlay
- (define question-1a
- (overlay (circle 10 "outline" "black") (circle 20 "outline" "black") (circle 30 "outline" "black") (circle 40 "outline" "black") (circle 50 "outline" "black")))
- (check-expect question-1a .)
- ;Part (b): using iterated-overlay
- (define question-1b
- (iterated-overlay (λ (circle-number)
- (circle (* 10 (+ 1 circle-number)) "outline" "black"))
- 5))
- (check-expect question-1b .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Question 2: Using iterated-beside
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define question-2
- (iterated-beside (λ (rectangle-number)
- (rectangle (* 10 (+ 1 rectangle-number)) 50 "outline" "black"))
- 7))
- (check-expect question-2 .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 3: A Simple Flower
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define question-3
- (iterated-overlay (λ (ellipse-number)
- (rotate (* 72 (+ ellipse-number 1)) (ellipse 100 25 "solid" "blue")))
- 5))
- (check-expect question-3 .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 4: A Colorful Flower
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define question-4
- (iterated-overlay (λ (ellipse-number)
- (rotate (* 72 ellipse-number) (ellipse 100 25 "solid" (color (* 25 ellipse-number) (- 255 (* 25 ellipse-number)) 0))))
- 5))
- (check-expect question-4 .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 5: A Fancy Flower
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define question-5
- (iterated-overlay (λ (ellipse-number)
- (rotate (* 72 ellipse-number) (ellipse 100 25 "solid" (interpolate-colors (color 0 0 255 100) (color 255 0 0 100) (if (equal? ellipse-number 4) 1 (* .25 ellipse-number))))))
- 5))
- (check-expect question-5 .)
- ;; Use this to test your colors.
- ;; Remember, your final answer must pass the previous test, so you should
- ;; only use this image as a temporary aid.
- ;; (define q5-colors .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 6: Paint Chips
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; purpose: return a row of n (given by the number argument)
- ; 50x50 squares where the colors of the squares interpolate
- ; between the two color arguments
- ; signature: swatch : color, color, number -> image
- (define swatch
- (λ (color1 color2 num-squares)
- (iterated-beside (λ (square-count)
- (rectangle 50 50 "solid" (interpolate-colors color1 color2 (if (equal? (- num-squares 1) square-count) 1 (* (/ 1 (- num-squares 1)) square-count)))))
- num-squares)))
- (check-expect (swatch (color 86 180 233) (color 213 94 0) 5)
- .)
- (check-expect (swatch (color 0 0 0) (color 255 255 255) 2)
- .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 7: Swatch Grids
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; purpose: return a grid with the given number of rows and columns
- ; where each row interpolates between the two color arguments and
- ; each column interpolates between the color of the top square and
- ; black (color 0 0 0) (see the pdf for more detail if this is confusing)
- ; NOTE: you MUST use your swatch function from the previous step
- ; signature: swatch-grid : color, color, number, number -> image
- (define swatch-grid
- (λ (color1 color2 num-rows num-cols)
- (iterated-above (λ (n)
- (swatch (interpolate-colors color1 (color 0 0 0) (* n (/ 1 num-rows)))
- (interpolate-colors color2 (color 0 0 0) (* n (/ 1 num-rows)))
- num-cols)) num-rows)))
- (check-expect (swatch-grid (color 86 180 233) (color 213 94 0) 5 5)
- .)
- (check-expect (swatch-grid (color 204 121 167) (color 0 158 115) 4 3)
- .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 8: Bullseye Revisited
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; purpose: Generates an image of a bullseye with the specified number of rings, radius length of the outer ring, and line color.
- ;; signature: bullseye/simple: num-rings, radius, line-color -> image
- (define bullseye/simple
- (λ (num-rings radius line-color)
- (iterated-overlay (λ (n)
- (circle (* (+ n 1) (/ radius num-rings))
- "outline" line-color))num-rings)))
- (check-expect (bullseye/simple 5 50 (color 0 0 0)) question-1b)
- (check-expect (bullseye/simple 5 50 (color 0 0 0)) question-1a)
- ; You must turn these images into test cases, using the information above the image
- ; 20 rings, radius of 100, line color - (color 86 180 233)
- (check-expect (bullseye/simple 20 100 (color 86 180 233))
- .)
- ; 3 rings, radius of 75, line color - (color 204 121 167)
- (check-expect (bullseye/simple 3 75 (color 204 121 167))
- .)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Question 9: Colorful Bullseye
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; purpose: Generastes a bullseye with a specified number of rings and the outermost radius having the specified radius with the outer ring to have the outer-color and inner circle to have the
- ; inner-color, while the colors evenly interpolate between the 2 specified colors.
- ;; signature: bullseye/color: num-rings radius inner-color outer-color -> image
- (define bullseye/color
- (λ (num-rings radius inner-color outer-color)
- (iterated-overlay (λ (n)
- (circle (* (+ n 1) (/ radius num-rings))
- "solid"
- (interpolate-colors inner-color outer-color (* n (/ 1 (- num-rings 1))))))num-rings)))
- ; turn the below images into test cases
- ; NOTE THE ORDER OF THE ARGUMENTS!
- ; 6 rings, radius 50, inner color (color 0 158 115), outer color (color 204 121 167)
- (check-expect (bullseye/color 6 50 (color 0 158 115) (color 204 121 167))
- .)
- ; 4 rings, radius 75, inner color (color 213 94 0), outer color (color 86 180 233)
- (check-expect (bullseye/color 4 75 (color 213 94 0) (color 86 180 233))
- .)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement