added line variables

This commit is contained in:
Thorn Avery 2019-12-07 21:52:14 +13:00
parent a286231271
commit 3529cf95ee
2 changed files with 22 additions and 9 deletions

View File

@ -3,14 +3,16 @@
(require graphics/value-turtles) (require graphics/value-turtles)
(require file/convertible) (require file/convertible)
(define forward 3) (define start '(X))
(define forward 4)
(define theta 20) (define theta 20)
(define generations 6) (define generations 7)
(define thick 8)
(define (tend sym) (define (tend sym)
(cond (cond
[(eq? sym 'F) '(F F)] [(eq? sym 'F) '(F F)]
[(eq? sym 'X) '(F m l l X r p X r p F l p F X r m X)] [(eq? sym 'X) '(d F m l l X r p X r p F l p F X r m X)]
[else `(,sym)])) [else `(,sym)]))
(define (season plant) (define (season plant)
@ -24,7 +26,7 @@
(define init-turtle (define init-turtle
(set-pen-width (turtles 600 800 300 400 (/ pi -2)) (set-pen-width (turtles 600 800 300 400 (/ pi -2))
1)) thick))
(define state '()) (define state '())
(define (step-turtle op turtle) (define (step-turtle op turtle)
@ -32,14 +34,25 @@
[(eq? op 'F) (draw forward turtle)] [(eq? op 'F) (draw forward turtle)]
[(eq? op 'm) (turn theta turtle)] [(eq? op 'm) (turn theta turtle)]
[(eq? op 'p) (turn (* -1 theta) turtle)] [(eq? op 'p) (turn (* -1 theta) turtle)]
[(eq? op 'u) (set-pen-width turtle
(+ 1 (turtles-pen-width turtle)))]
[(eq? op 'd) (set-pen-width turtle
(- (turtles-pen-width turtle) 1))]
[(eq? op 'l) (begin (set! state [(eq? op 'l) (begin (set! state
(cons (turtle-state turtle) (cons (turtle-state turtle)
state)) state))
(set! thick
(cons (turtles-pen-width turtle)
thick))
turtle)] turtle)]
[(eq? op 'r) (restore-turtle-state turtle [(eq? op 'r) (let ([s (car state)]
(begin (let ([s (car state)]) [t (car thick)])
(set! state (cdr state)) (begin
s)))] (set! state (cdr state))
(set! thick (cdr thick))
(set-pen-width
(restore-turtle-state turtle s)
t)))]
[else turtle])) [else turtle]))
(define (run-turtle plant turtle) (define (run-turtle plant turtle)
@ -54,7 +67,7 @@
(write-bytes pict file))) (write-bytes pict file)))
(define (test-plant) (define (test-plant)
(let ([plant (grow '(X) generations)]) (let ([plant (grow start generations)])
(begin (set! state '()) (begin (set! state '())
(write-plant (run-turtle plant init-turtle) (write-plant (run-turtle plant init-turtle)
"test-plant.png")))) "test-plant.png"))))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 186 KiB