Exemplo n.º 1
0
scale = 0.5
grammar.add_non_terminal('Scale', [
    lambda turtle: turtle.scale(scale),
    lambda turtle: turtle.scale_thickness(0.6),
])
grammar.add_non_terminal('Scale', [])

grammar.add_non_terminal('Tree', [
    lambda turtle: turtle.store(),
    'Forward Left',
    'Scale',
    'Tree',
    lambda turtle: turtle.restore(),
    lambda turtle: turtle.store(),
    'Forward Right',
    'Scale',
    'Tree',
    lambda turtle: turtle.restore(),
], 8)

grammar.add_non_terminal('Tree', [])

#for i in range(0, 5):
backend = SVGBackend()
turtle = ThickTurtle(backend)
turtle.thickness = 0.05

grammar.expand('Root', turtle, 20)
backend.write('flower3.svg')
Exemplo n.º 2
0
from svg_backend import SVGBackend
from turtle import Turtle
from grammar import Grammar

backend = SVGBackend()
turtle = Turtle(backend)

grammar = Grammar()

grammar.add_non_terminal('RS', [
    lambda turtle: turtle.forward(2), 
    lambda turtle: turtle.turn_right(89.9),
    lambda turtle: turtle.scale(1.00001),
    'RS'])

grammar.expand('RS', turtle, 300)
backend.write('rect_spiral.svg')
Exemplo n.º 3
0
from svg_backend import SVGBackend
from turtle import Turtle
from grammar import Grammar
from turtle import ThickTurtle
from turtle import NarrowingTurtle

backend = SVGBackend()
turtle = Turtle(backend)
grammar = Grammar()

right_segment = [
    lambda turtle: turtle.forward(0.1), lambda turtle: turtle.turn_right(5)
]

left_segment = [
    lambda turtle: turtle.forward(0.1), lambda turtle: turtle.turn_left(5)
]

#grammar.add_non_terminal('Left', left_segment * 7)
#grammar.add_non_terminal('Left', left_segment * 10)
grammar.add_non_terminal('Left', left_segment * 13)

#grammar.add_non_terminal('Right', right_segment * 7)
#grammar.add_non_terminal('Right', right_segment * 10)
grammar.add_non_terminal('Right', right_segment * 13)

scale = 0.5

grammar.add_non_terminal('Tree', [
    lambda turtle: turtle.store(),
    'Left',
Exemplo n.º 4
0
from svg_backend import SVGBackend
from turtle import Turtle
from grammar import Grammar

backend = SVGBackend()
turtle = Turtle(backend)

turtle.turn_right(180.0)

grammar = Grammar()

grammar.add_non_terminal('S', [
    lambda turtle: turtle.forward(), lambda turtle: turtle.turn_right(5),
    lambda turtle: turtle.scale(0.99), 'S'
])

grammar.expand('S', turtle, 500)
backend.write('spiral.svg')