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()
#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()
#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
#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.
0 Comments