Lsystems/Python/Arbre1.py

66 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
from turtle import *
# Génération de plante
def regle():
nbiteration = 5
longueur = 3
angle = 25.7
regle = 'F[+F]F[-F]F'
#regle = 'F+FF-FF-F-F+F+FF-F-F+F+FF+FF-F'
axiom = 'F'
i = 0
while i < nbiteration:
j = 0
axiom2 = ''
while j < len(axiom):
pointeur1 = axiom[j]
if pointeur1 == 'F':
axiom2 = axiom2 + regle
if pointeur1 == '+':
axiom2 = axiom2 + '+'
if pointeur1 == '-':
axiom2 = axiom2 + '-'
if pointeur1 == '[':
axiom2 = axiom2 + '['
if pointeur1 == ']':
axiom2 = axiom2 + ']'
j = j + 1
axiom = axiom2
i = i + 1
print axiom
k = 0
laposition = []
langle = []
while k < len(axiom):
pointeur2 = axiom[k]
if pointeur2 == 'F':
forward(longueur)
elif pointeur2 == '+':
left(angle)
elif pointeur2 == '-':
right(angle)
elif pointeur2 == '[':
laposition.append(position())
langle.append(heading())
elif pointeur2 == ']':
goto(laposition[len(laposition)-1][0], laposition[len(laposition)-1][1])
del laposition[len(laposition)-1]
setheading(langle[len(langle)-1])
del langle[len(langle)-1]
k = k + 1
up()
#left(180)
#forward(400)
#left(90)
#forward(200)
#left(90)
#down()
backward(495)
down()
regle()
#quit()