Advertisement
Guest User

Untitled

a guest
Oct 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 6.63 KB | None | 0 0
  1. ; Olivier Gabison
  2. (require 2htdp/image)
  3. (require "./iterated-images.rkt")
  4.  
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. ; Question 1: Using iterated-overlay
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9.  ;Part (a): using overlay
  10. (define question-1a
  11.   (overlay (circle 10 "outline" "black") (circle 20 "outline" "black") (circle 30 "outline" "black") (circle 40 "outline" "black") (circle 50 "outline" "black")))
  12.  
  13. (check-expect question-1a .)
  14.  
  15.  ;Part (b): using iterated-overlay
  16. (define question-1b
  17.     (iterated-overlay (λ (circle-number)
  18.                         (circle (* 10 (+ 1 circle-number)) "outline" "black"))
  19.                       5))
  20.                        
  21.  
  22. (check-expect question-1b .)
  23.  
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ; Question 2: Using iterated-beside
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27.  
  28. (define question-2
  29.   (iterated-beside (λ (rectangle-number)
  30.                      (rectangle (* 10 (+ 1 rectangle-number)) 50 "outline" "black"))
  31.                    7))
  32.  
  33. (check-expect question-2 .)
  34.  
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;; Question 3: A Simple Flower
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38.  
  39. (define question-3
  40.   (iterated-overlay (λ (ellipse-number)
  41.                       (rotate (* 72 (+ ellipse-number 1)) (ellipse 100 25 "solid" "blue")))
  42.                       5))
  43.  
  44. (check-expect question-3 .)
  45.  
  46. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  47. ;; Question 4: A Colorful Flower
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49.  
  50. (define question-4
  51.   (iterated-overlay (λ (ellipse-number)
  52.                       (rotate (* 72 ellipse-number) (ellipse 100 25 "solid" (color (* 25 ellipse-number) (- 255 (* 25 ellipse-number)) 0))))
  53.                       5))
  54.  
  55. (check-expect question-4 .)
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;; Question 5: A Fancy Flower
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.  
  61. (define question-5
  62.     (iterated-overlay (λ (ellipse-number)
  63.                       (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))))))
  64.                       5))
  65.  
  66. (check-expect question-5 .)
  67.  
  68. ;; Use this to test your colors.
  69. ;; Remember, your final answer must pass the previous test, so you should
  70. ;; only use this image as a temporary aid.
  71.  
  72. ;; (define q5-colors .)
  73.  
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;; Question 6: Paint Chips
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77.  
  78. ; purpose: return a row of n (given by the number argument)
  79. ; 50x50 squares where the colors of the squares interpolate
  80. ; between the two color arguments
  81. ; signature: swatch : color, color, number -> image
  82. (define swatch
  83.   (λ (color1 color2 num-squares)
  84.     (iterated-beside (λ (square-count)
  85.                        (rectangle 50 50 "solid" (interpolate-colors color1 color2 (if (equal? (- num-squares 1) square-count) 1 (* (/ 1 (- num-squares 1)) square-count)))))
  86.                      num-squares)))
  87.  
  88. (check-expect (swatch (color 86 180 233) (color 213 94 0) 5)
  89.               .)
  90. (check-expect (swatch (color 0 0 0) (color 255 255 255) 2)
  91.               .)
  92.  
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ;; Question 7: Swatch Grids
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96.  
  97. ; purpose: return a grid with the given number of rows and columns
  98. ; where each row interpolates between the two color arguments and
  99. ; each column interpolates between the color of the top square and
  100. ; black (color 0 0 0) (see the pdf for more detail if this is confusing)
  101. ; NOTE: you MUST use your swatch function from the previous step
  102. ; signature: swatch-grid : color, color, number, number -> image
  103. (define swatch-grid
  104.   (λ (color1 color2 num-rows num-cols)
  105.     (iterated-above (λ (n)
  106.                       (swatch (interpolate-colors color1 (color 0 0 0) (* n (/ 1 num-rows)))
  107.                               (interpolate-colors color2 (color 0 0 0) (* n (/ 1 num-rows)))
  108.                               num-cols)) num-rows)))
  109.  
  110. (check-expect (swatch-grid (color 86 180 233) (color 213 94 0) 5 5)
  111.               .)
  112. (check-expect (swatch-grid (color 204 121 167) (color 0 158 115) 4 3)
  113.               .)
  114.  
  115. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  116. ;; Question 8: Bullseye Revisited
  117. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  118.  
  119. ;; purpose: Generates an image of a bullseye with the specified number of rings, radius length of the outer ring, and line color.
  120. ;; signature: bullseye/simple: num-rings, radius, line-color -> image
  121. (define bullseye/simple
  122.   (λ (num-rings radius line-color)
  123.     (iterated-overlay (λ (n)
  124.                         (circle (* (+ n 1) (/ radius num-rings))
  125.                                 "outline" line-color))num-rings)))
  126.  
  127. (check-expect (bullseye/simple 5 50 (color 0 0 0)) question-1b)
  128. (check-expect (bullseye/simple 5 50 (color 0 0 0)) question-1a)
  129.  
  130. ; You must turn these images into test cases, using the information above the image
  131.  
  132. ; 20 rings, radius of 100, line color - (color 86 180 233)
  133. (check-expect (bullseye/simple 20 100 (color 86 180 233))
  134.  .)
  135.  
  136. ; 3 rings, radius of 75, line color - (color 204 121 167)
  137. (check-expect (bullseye/simple 3 75 (color 204 121 167))
  138.  .)
  139.  
  140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  141. ;; Question 9: Colorful Bullseye
  142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143.  
  144. ;; 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
  145. ; inner-color, while the colors evenly interpolate between the 2 specified colors.
  146. ;; signature: bullseye/color: num-rings radius inner-color outer-color -> image
  147. (define bullseye/color
  148.   (λ (num-rings radius inner-color outer-color)
  149.     (iterated-overlay (λ (n)
  150.                         (circle (* (+ n 1) (/ radius num-rings))
  151.                                 "solid"
  152.                                 (interpolate-colors inner-color outer-color (* n (/ 1 (- num-rings 1))))))num-rings)))
  153.  
  154. ; turn the below images into test cases
  155. ; NOTE THE ORDER OF THE ARGUMENTS!
  156. ; 6 rings, radius 50, inner color (color 0 158 115), outer color (color 204 121 167)
  157. (check-expect (bullseye/color 6 50 (color 0 158 115) (color 204 121 167))
  158.  
  159.  .)
  160.  
  161. ; 4 rings, radius 75, inner color (color 213 94 0), outer color (color 86 180 233)
  162. (check-expect (bullseye/color 4 75 (color 213 94 0) (color 86 180 233))
  163.  
  164.  .)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement