c-wrapperとSDLと自作のL-systemライブラリを使ってドラゴン曲線を描いてみた.
(use klib.list)
(use klib.sdl)
(use klib.turtle)
(use klib.l-system)
(define-rule x->x 'x '(x + y f))
(define-rule y->x 'y '(f x - y))
(define gen (make <G> :init '(f x) :rules `(,x->x ,y->x)))
(define (dragon-curve n level)
(convert (gen level)
`(f . ,(lambda (x) (forward (/. n (expt 1.4 level)))))
`(+ . ,(lambda (x) (turn 90)))
`(- . ,(lambda (x) (turn -90)))
`(x . ,(lambda (x) (turn 0)))
`(y . ,(lambda (x) (turn 0)))
))
(define (main args)
(set-caption! "Dragon Curve")
(turtle-main args
(color (make <color> :r 0 :g 0))
(move 300)
(dragon-curve 250 13)
))
|
[7回]