Tuesday, April 5, 2016

Fractal Tree using Python with Turtle Module

Here is "minus one" nearly symmetrical fractal tree
import turtle
import numpy

#buat pola di sini
#kura-kura menghadap ke atas
turtle.shape("turtle")
turtle.left(90)


lv  = 7
l   = 100
s   = 17

turtle.penup()
turtle.backward(l)
turtle.pendown()
turtle.forward(l)


def maju(l,level):
    l           = 3./4.*l
    turtle.left(s)
    turtle.forward(l)
    if level<lv:
        level   +=1
        maju(l,level)
    
    turtle.backward(l)
    turtle.right(2*s)
    turtle.forward(l)
    if level<lv:
        maju(l,level)
    turtle.backward(l)
    turtle.left(s)
    level       -=1

maju(l,2)


#agar gambar tak langsung hilang
turtle.exitonclick()



 


.



if we want symmetrical result, just move 
level +=1 
syntax
to the place before first if