;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Sierp Types ;; A Sierp is a self-similar struture that is either ;; -- SierpBase ;; -- list-of-Sierp ;; The base-case Sierpinski structure that has ;; has 3 posns in clockwise order from the top: ;; top, lower right, lower left (define-struct SierpBase (top lr ll)) ;; A list-of-Sierp is a list and is either ;; -- empty ;; -- (cons Sierp list-of-Sierp) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions for creating Sierpinski gaskets. ;; Makes an equilateral triangle with a base of width. ;; This is a base case Sierpinski gasket. (define (make-FullSizeSierp width) (local [(define width_2 (/ width 2)) (define root3 (sqrt 3))] (make-SierpBase (make-posn width_2 0) (make-posn 0 (* width_2 root3)) (make-posn width (* width_2 root3))))) ;; getMidPt: posn posn --> posn ;; Returns the mid-point between two posns. (define (getMidPt p1 p2) (make-posn (/ (+ (posn-x p1) (posn-x p2)) 2) (/ (+ (posn-y p1) (posn-y p2)) 2))) ;; make-nextSierp: SierpBase --> list-of-Sierp ;; Takes a SierpBase and returns a list-of-Sierp filled with 3 SierpBases ;; where the SierpBases are formed from the vertices of the input ;; SierpBase and the mid-points of its sides. ;; The 3 SierpBases are in clockwise order from the top of the input SierpBase. (define (make-nextSierp sierpBase) (local [(define midTopLr (getMidPt (SierpBase-top sierpBase) (SierpBase-lr sierpBase))) (define midLrLl (getMidPt (SierpBase-lr sierpBase) (SierpBase-ll sierpBase))) (define midLlTop (getMidPt (SierpBase-ll sierpBase) (SierpBase-top sierpBase)))] (list (make-SierpBase (SierpBase-top sierpBase) midTopLr midLlTop) (make-SierpBase midTopLr (SierpBase-lr sierpBase) midLrLl) (make-SierpBase midLlTop midLrLl (SierpBase-ll sierpBase))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions for drawing Sierpinski gaskets. ;; Incomplete -- How to draw inductive case? ;; draw-sierpBase: SierpBase --> boolean ;; Draws a SierpBase on the output canvas. (define (draw-sierpBase sierpBase) (and (draw-solid-line (SierpBase-top sierpBase) (SierpBase-lr sierpBase)) (draw-solid-line (SierpBase-lr sierpBase) (SierpBase-ll sierpBase)) (draw-solid-line (SierpBase-ll sierpBase) (SierpBase-top sierpBase)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "Sierp test cases:" (define width 500) (define s1 (make-FullSizeSierp width)) (define s1_next (make-nextSierp s1)) (start width width) (draw-sierpBase s1)