Ejemplo n.º 1
0
from svg_backend import SVGBackend
from turtle import Turtle
from grammar import Grammar
from turtle import ThickTurtle
from turtle import NarrowingTurtle

grammar = Grammar()

grammar.add_non_terminal(
    'Forward Right',
    [lambda turtle: turtle.forward(1.0), lambda turtle: turtle.turn_right(60)])
grammar.add_non_terminal(
    'Forward Left',
    [lambda turtle: turtle.forward(1.0), lambda turtle: turtle.turn_left(60)])

grammar.add_non_terminal('Root', [
    'Tree',
    lambda turtle: turtle.turn_left(120),
    'Tree',
    lambda turtle: turtle.turn_left(120),
    'Tree',
])

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', [
Ejemplo 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')
Ejemplo n.º 3
0
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',
    lambda turtle: turtle.scale(scale),
    'Tree',
    lambda turtle: turtle.restore(),
    'Right',
    lambda turtle: turtle.scale(scale),
Ejemplo 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')