Animation in Python | Turtle in Python

Hello friends how are you, Today in this post "Animation in Python | Turtle 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 some interesting and creative shapes that make you happy today. 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.

Now i am going to explain some shapes one by one.

1.Colorful Star Pattern : To make this star pattern more interesting i have filled each line of this star pattern with different color, and also increased the width of the line. Here is the source code of this pattern

#import turtle library
import  turtle
#list for storing color
mycolor=["red","blue","yellow","green","orange"]
#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)
j=0
for i in range(5):
    #set color for each line
    turtle.pencolor(mycolor[j])
    j+=1
    turtle.forward(200)
    turtle.right(144)
turtle.done()

Here in the above code i have already explained each line of code with comment. You just need to type this code into your python file or you can copy this code for your personal use. When you will run this python code you will get output like below

Turtle in Python

2. Colorful Hexagonal Pattern : I have applied different color in each line of the Hexagonal shape to make it more interesting. Here is the complete code for this shape

#import turtle library
import  turtle
#list for storing color
mycolor=["red","blue","yellow","green","orange","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)
j=0
for i in range(0,6):
    #set different color in each line
    turtle.pencolor(mycolor[j])
    j+=1
    turtle.forward(100)
    turtle.left(60)
turtle.done()

Here just type this code your python file and run program you will get output like below

Turtle in Python

3. Colorful Nested Rectangle Pattern : I have made a Nested Rectangle type pattern in which all rectangle's one side is filled with same color and another side with different color and these changes are making it more interesting. here is the complete code for this pattern

#import turtle library
import  turtle
#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(5)
#using loop
mycolor=["red","blue","yellow","green","orange"]
k=0
j=200
for i in range(0,17,1):
    turtle.pencolor(mycolor[k])
    k+=1
    if k==4:
        k=0
    turtle.forward(j)
    j=j-10
    turtle.left(90)

turtle.done()

Just type this code into your python file and run this code you will get an output screen like below

Turtle in Python

4.Colorful Spiral Pattern : This pattern is the most important pattern in Python Turtle because it looks like magic is happening in front of our eyes. Here is the complete code for this pattern

#import the needed library
import  turtle
import  time
#defining function
def myFun():
    #list for storing colors
    mycolors=["red","blue","green","yellow","orange","brown"]
    #creating turtle variable
    t=turtle
    #setting pensize 
    t.pensize(5)
    #setting background color
    t.bgcolor('black')
    #setting speed of drawing
    t.speed(1000)
    #loop for creating design
    for x in range(360):
        t.pencolor(mycolors[x%len(mycolors)])
        t.pensize(x/50)
        t.forward(x)
        t.left(59)
myFun()
time.sleep(5)

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.

Turtle 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