Difference between revisions of "Sierpinski Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 68: Line 68:
  
 
{{RacketToImplement|cantor|cantor-stool|sierpinski_and_cantor}}
 
{{RacketToImplement|cantor|cantor-stool|sierpinski_and_cantor}}
 
==Stool==
 
<nowiki>(define (cantor-stool width height n)
 
  (raise 'not-yet-implemented #t))</nowiki>
 
 
{| class="wikitable" style="text-align: center; "
 
|[[File:Cantor-stool_0.svg|200px]]
 
|[[File:Cantor-stool_1.svg|200px]]
 
|[[File:Cantor-stool_2.svg|200px]]
 
|[[File:Cantor-stool_3.svg|200px]]
 
|[[File:Cantor-stool_4.svg|200px]]
 
|-
 
|n=0
 
|n=1
 
|n=2
 
|n=3
 
|n=4
 
|}
 
 
 
Note: you have been provided with a function which draws a red rectangle outlined in blue.
 
 
(define (brick w h)
 
  (overlay
 
  (rectangle w h "outline" "blue")
 
  (rectangle w h "solid" "red")
 
  )
 
  )
 

Revision as of 18:14, 1 February 2023

Motivation

We will recursively generate some images with the Racket Image Library.

Code To Investigate

placement

shapes

Spacer

; fully transparent rectangle
(define (spacer-rect w h)
  (rectangle w h "outline" (color 0 0 0 0)))

; fully transparent image the size of img
(define (spacer-image img)
  (spacer-rect (image-width img) (image-height img)))

Sierpiński

file: src/main/racket/sierpinski_and_cantor/sierpinski.rkt Racket-logo.svg
functions: sierpinski-triangle
sierpinski-carpet

Triangle

Sierpiński Triangle

(define (sierpinski-triangle side-length n)
  (raise 'not-yet-implemented #t))
Sierpinski-triangle 0.svg Sierpinski-triangle 1.svg Sierpinski-triangle 2.svg Sierpinski-triangle 3.svg Sierpinski-triangle 4.svg
n=0 n=1 n=2 n=3 n=4

Note: this has a remarkably clean solution. It is almost as if the Racket Image Library was created to build the Sierpiński Triangle.

Carpet

(define (sierpinski-carpet side-length n)
  (raise 'not-yet-implemented #t))
Sierpinski-carpet 0.svg Sierpinski-carpet 1.svg Sierpinski-carpet 2.svg Sierpinski-carpet 3.svg Sierpinski-carpet 4.svg.png
n=0 n=1 n=2 n=3 n=4

Cantor

Cantor set

file: src/main/racket/sierpinski_and_cantor/cantor.rkt Racket-logo.svg
functions: cantor-stool