(define (fractal phase r w n k)
(if (> n 0)
(let* ((theta (* phase pi/3))
(x (* r (cos theta)))
(y (* r (sin theta)))
(r (* r k)))
(set-line-width w
(overlay (segment (vec x y))
(at x y (fractal (phase+1 phase)
r (* w k) (- n 1) k))
(at x y (fractal (phase-1 phase)
r (* w k) (- n 1) k)))))
null-box))
(define (make-fractal r w n)
(let* ((k 0.618)
(box (overlay (fractal 0 r w n k)
(fractal 2 r w n k)
(fractal 4 r w n k))))
(draw-to-file-for-png "fractal" box)))
(define pi (acos -1))
(define pi/3 (/ pi 3))
(define (phase+1 phase) (if (= phase 5) 0 (+ phase 1)))
(define (phase-1 phase) (if (= phase 0) 5 (- phase 1)))
(make-fractal (* points-per-inch 1.5) 2 9)