Advertisement
Guest User

Untitled

a guest
Oct 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 2.92 KB | None | 0 0
  1. (require 2htdp/image)
  2. (require "iterated-images.rkt")
  3.  
  4. ;; double: image -> image
  5. ;; Makes an image that looks like two copies of its input, side-by-side
  6. (define double
  7.   (λ (image)
  8.     (beside image image)))
  9.  
  10. (check-expect (double (square 100 "outline" "black"))
  11.               .)
  12.  
  13. ;; triple: image -> image
  14. ;; Makes an image that looks like three copies of its input, side-by-side
  15. (define triple
  16.   (λ (image)
  17.    (beside image image image)))
  18.  
  19. (check-expect (triple (square 50 "outline" "black"))
  20.               .)
  21.  
  22. ;; bracket: image image -> image
  23. ;; Makes an image with the center image surrounded on the left and right by the enclosing-image
  24. (define bracket
  25.   (λ (center enclosing)
  26.     (beside enclosing center enclosing)))
  27.  
  28. (check-expect (bracket (square 100 "solid" "red")
  29.                        (circle 50 "solid" "blue"))
  30.               .)
  31.  
  32. ;; multiply: image number -> image
  33. ;; Makes an image that contains a specified number of copies of its input
  34. (define multiply
  35.   (λ (image count)
  36.     (iterated-beside (λ (image-number)  ;; The image-making procedure
  37.                        image)
  38.                      ;; The number of times to call the image-making procedure
  39.                     count)))
  40.  
  41. (check-expect (multiply (circle 30 "solid" "blue")
  42.                         5)
  43.               .)
  44.  
  45. ;; bullseye: number -> image
  46. ;; Makes a pattern of concentric circles, starting with a 20 pixel circle, then a 40 pixel, etc.
  47. (define bullseye
  48.   (λ (circle-count)
  49.     (iterated-overlay (λ (circle-number)
  50.                         (circle (* 20 (+ 1 circle-number)) "outline" "black"))
  51.                       circle-count)))
  52.  
  53. (check-expect (bullseye 5)
  54.               .)
  55.  
  56. ;; color-bullseye: number number -> image
  57. ;; Makes a pattern of concentric circles, starting with a 20 pixel circle, then a 40 pixel, etc.
  58. ;; The innermost circle should be black, the one surrounding it should have rate-of-brightening
  59. ;; units of green light, but not red or blue, the one around it should have (* 2 rate-of-brightening)
  60. ;; units of green, the one around it should have (* 3 rate-of-brightening) units of green, and so on.
  61. ;;(rgb red green blue)
  62. (define color-bullseye
  63.   (λ (circle-count rate-of-brightening)
  64.     (iterated-overlay (λ (circle-number)
  65.                         (circle (* 20 (+ 1 circle-number)) "solid" (color 0 (* rate-of-brightening circle-number) 0)))
  66.                 circle-count)))
  67.    
  68.  
  69.  
  70.  
  71. (check-expect (color-bullseye 5 50)
  72.               .)
  73.  
  74. ;; ziggurat: count color -> image
  75. ;; Make a stepped pyramid in the specified color with the specified number of steps.
  76. ;; The top step should be 10x10 pixels, and each successive step should be 20 pixels wider.
  77. (define ziggurat
  78.   (λ (steps color)
  79.     (iterated-above (λ (step-number)
  80.                       (rectangle (- (* 20 (+ 1 step-number)) 10) 10 "solid" color))
  81.                     steps)))
  82.  
  83. (check-expect (ziggurat 10 "purple")
  84.               .)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement