Create Tree with Animation in Python | Python Turtle

Hello friends how are you, Today in this post "Create Tree with Animation in Python" i am going to teach something more interesting in Python which is Python Turtle Graphics. This is the library which is used to create many shapes. Turtle module provides many predefined functions and by using these function we can create many interesting graphics layout.

Here in this particular post i will teach you how you can create a Tree in Python with Animation using Turtle. If you are a Computer Science students then this post will help you definitely. Turtle is very easy to learn if you don't know Turtle then click here Turtle in Python to learn complete Turtle from basic to advance level.

Step 1: Install Python : Click here to watch a video on how to install python or Open any browser and type Download Python and click the first link you will get official website of python here you will get a Download button and after clicking on this button you will get exe of latest python version just install it into your system. 

Step 2: Install Pycharm | Create Project | Install LibraryClick here to watch a single video on How to install Pycharm | Create Project | Install Library  or To install Pycharm IDE Open any browser and type Download Pycharm and click the first link you will get official website of Pycharm  here you will get a black download button and after clicking on this button you will get an exe of Pycharm , just install it into your system. 

Learn Python:Want to learn complete python for free click here 

Step 3: Create Project : Open Pycharm  click on File which is in top left of screen and select New Project. Then you will get a screen. Here first you need to select directory of your project and then type a name for your project like "PythonTree" after directory name, and at last click the create button to create this project. 

Step 4: Create Python file: To create a python file for coding in your project just right click on project name "PythonTree" and select new and click on Python File , you will get popup screen in which you have to type a name like "Program" for python file and press enter, it will create a python file with name Program.py inside the project PythonTree. 

5.Python code : Here is the complete code for creating tree in python with animation.

#import turtle library
import  turtle
#list for storing color
mycolor=["red","blue","yellow","green","orange","pink","red","blue","yellow","green","orange","pink","navy"]
#set background to black
turtle.bgcolor("black")
#set pencolor to orange
turtle.pencolor("yellow")
turtle.color("yellow","green")
#change pen shape
turtle.shape("turtle")
turtle.pensize(10)
turtle.rt(270)
j=0
for i in range(13):
    #set color for each line
    turtle.pencolor(mycolor[j])
    j+=1
    turtle.forward(200)
    turtle.right(194)
#changing pensize
turtle.pensize(15)
turtle.pencolor("green")
turtle.lt(182)
turtle.fd(300)
turtle.rt(360)
turtle.backward(100)

turtle.pensize(10)
for m in range(0,15):
 turtle.rt(m)
 turtle.backward(m+7) 
turtle.pensize(5)
j=0
for i in range(13):
    #set color for each line
    turtle.pencolor(mycolor[j])
    j+=1
    turtle.forward(70)
    turtle.right(194)
turtle.done()

You need to type this code or you can copy this code for your personal use and paste it to your python file and run this code you will get output screen like below.

Animation in Python


Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks.😊

Post a Comment

0 Comments