Draw Life of Tree in Python Using Turtle

Python Program to Draw Life of Tree Using Turtle

# Draw Life of Tree in Python Using Turtle
import turtle as tu


roo = tu.Turtle() #Turtle object
wn = tu.Screen() #Screen Object
wn.bgcolor("black") #Screen Bg color 
roo.left(90) #moving the turtle 90 degrees towards left
roo.speed(20) #setting the speed of the turtle

#recursive function taking length 'l' as argument
def  draw(l):
    if(l<10):
        return
    else:

        roo.pensize(2) #Setting Pensize
        roo.pencolor("yellow") #Setting Pencolor as yellow
        roo.forward(l) #moving turtle forward by 'l'
        roo.left(30) #moving the turtle 30 degrees towards left
        draw(3*l/4) #drawing a fractal on the left of the turtle object 'roo' with 3/4th of its length
        roo.right(60) #moving the turtle 60 degrees towards right
        draw(3*l/4) #drawing a fractal on the right of the turtle object 'roo' with 3/4th of its length
        roo.left(30) #moving the turtle 30 degrees towards left
        roo.pensize(2)
        roo.backward(l) #returning the turtle back to its original psition

draw (20) # drawing 20 times 

roo.right(90)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("magenta") #magenta
        roo.forward(l)
        roo.left(30)
        draw(3*l/4)
        roo.right(60)
        draw(3*l/4)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)

draw (20)


roo.left(270)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("red") #red
        roo.forward(l)
        roo.left(30)
        draw(3*l/4)
        roo.right(60)
        draw(3*l/4)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)

draw (20)

roo.right(90)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(2)
        roo.pencolor('#FFF8DC') #white
        roo.forward(l)
        roo.left(30)
        draw(3*l/4)
        roo.right(60)
        draw(3*l/4)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)

draw(20)
########################################################

def  draw(l):
    if(l<10):
        return
    else:

        roo.pensize(3)
        roo.pencolor("lightgreen") #lightgreen
        roo.forward(l)
        roo.left(30)
        draw(4*l/5)
        roo.right(60)
        draw(4*l/5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)

draw (40)

roo.right(90)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(3)
        roo.pencolor("red") #red
        roo.forward(l)
        roo.left(30)
        draw(4*l/5)
        roo.right(60)
        draw(4*l/5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)

draw (40)


roo.left(270)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(3)
        roo.pencolor("yellow") #yellow
        roo.forward(l)
        roo.left(30)
        draw(4*l/5)
        roo.right(60)
        draw(4*l/5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)

draw (40)

roo.right(90)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(3)
        roo.pencolor('#FFF8DC') #white
        roo.forward(l)
        roo.left(30)
        draw(4*l/5)
        roo.right(60)
        draw(4*l/5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)

draw (40)

########################################################
def  draw(l):
    if(l<10):
        return
    else:
        
        roo.pensize(2)
        roo.pencolor("cyan") #cyan
        roo.forward(l)
        roo.left(30)
        draw(6*l/7)
        roo.right(60)
        draw(6*l/7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)
        
draw (60)

roo.right(90)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("yellow") #yellow
        roo.forward(l)
        roo.left(30)
        draw(6*l/7)
        roo.right(60)
        draw(6*l/7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)
        
draw (60)


roo.left(270)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("magenta") #magenta
        roo.forward(l)
        roo.left(30)
        draw(6*l/7)
        roo.right(60)
        draw(6*l/7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)
        
draw (60)

roo.right(90)
roo.speed(2000)

#recursion
def  draw(l):
    if(l<10):
        return
    else:
        roo.pensize(2)
        roo.pencolor('#FFF8DC') #white
        roo.forward(l)
        roo.left(30)
        draw(6*l/7)
        roo.right(60)
        draw(6*l/7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)
draw(60)
wn.exitonclick()

Output:

About The Author

Leave a Reply