;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;; Remember to use the draw.ss teachpack ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;; Number -> Boolean ;; termination case: returns whether the side of a square ;; is too small to continue dividing (define (too-small? len) (< len 1)) ;; Posn Posn Posn Posn -> true ;; draw a square from the input posns and return true ;; side effect: square is drawn on screen (define (draw-square a b c d) (and (draw-solid-line a b) (draw-solid-line b c) (draw-solid-line c d) (draw-solid-line d a))) ;; Number Posn -> true ;; draws a fractal using side length len and top corner p ;; this fractal is recursively four squares inside another ;; square, like so. ;; ;; *----------*----------*----------* ;; | | | | ;; | | | | ;; | | | | ;; | | | | ;; | | | | ;; | *----------* | ;; | | ;; *----------* *----------* ;; | | | | ;; | | | | ;; | | | | ;; | | | | ;; | | | | ;; *----------* *----------* ;; | | ;; | *----------* | ;; | | | | ;; | | | | ;; | | | | ;; | | | | ;; | | | | ;; *----------*----------*----------* (define (fractal len p) (cond [(too-small? len) true] [else (local ((define x (posn-x p)) (define y (posn-y p)) (define a (make-posn (+ x len) y)) (define b (make-posn (+ x len) (+ len y))) (define c (make-posn x (+ len y))) (define newlen (/ len 3)) (define p1 (make-posn x (+ newlen y))) (define p2 (make-posn (+ x newlen) y)) (define p3 (make-posn (+ x (* 2/3 len)) (+ y newlen))) (define p4 (make-posn (+ x newlen) (+ y (* 2/3 len))))) (and (draw-square p a b c) (fractal newlen p1) (fractal newlen p2) (fractal newlen p3) (fractal newlen p4)))])) (start 600 600) (fractal 500 (make-posn 10 10)