Reputation: 155
If we want to draw a recursive art in scheme like the one above, how should we approach it?
Here is a rough draft that I have (not quite work as of now) edited from sierpinski triangle in scheme.
Thanks!
(define (hax fn)
(repeat 6 (lambda () (fn) (lt 60))))
(define (haxa d k)
(hax (lambda ()
(if (= k 1) (fd d) (haxaleg d k)))))
(define (haxaleg d k)
(haxa (/ d 2) (- k 1))
(penup)
(fd (* d 1.72))
(lt 120)
(pendown))
Upvotes: 1
Views: 1670
Reputation: 6315
As you seem to want to recursively draw smaller hexagons at each second corner around a hexagon, the following method shoud work.
In your dialect of scheme, this should be
(define (hexagon length)
(pendown)
(repeat 6 (lambda ()
(fd length)
(lt 60)))
(penup))
(define (hexagons length levels)
(hexagon length) ;; Draw big hexagon
(if (> levels 1)
(repeat 3 (lambda ()
(hexagons (/ length 2) (- levels 1)) ;; Then smaller ones,
(repeat 2 (lambda () ;; move to next corner
(fd length)
(lt 60)))))))
Upvotes: 3