This tutorial demonstrate how to draw basic shapes with python turtle. turtle is a small package which uses to draw basic shapes to some complex shapes. You can go to the Turtle documentation page for further information.
First of all you need to import turtle package to your project.
from turtle import *
Then you need to define line color and fill color. I choose line color as #FFD445 and fill color as #3475a9
color('#FFD445', '#3475a9')
Now I am ready to draw shapes. before we start drawing we need to invoke begin_fill()
method and need to invoke end_fill()
after the drawing.
Lets draw some basic shapes with turtle. !
Shape #1 - Line
We need to call
#!/usr/bin/python3
from turtle import *
color('#FFD445', '#3475a9')
goto(0,0)
forward(200)
done()
method to avoid immediate closing the turtle window.
#!/usr/bin/python3
from turtle import *
color('#FFD445', '#3475a9')
goto(0,0)
forward(200)
done()
Shape #2 - Square
#!/usr/bin/python3
from turtle import *
color('#FFD445', '#3475a9')
goto(0,0) #turtle goes to (0,0) coordinate position
begin_fill() #begining of filling
for i in range(4):
forward(200) #draw 200 lenghy line
left(90) # turn 90 degrees to left hand side
end_fill() #ending the filling
done()
Shape #3 - Circle
#!/usr/bin/python3
from turtle import *
color('#FFD445', '#3475a9')
goto(0,0) #turtle goes to (0,0) coordinate position
begin_fill() #begining of filling
circle(150) #circle with radius of 150
end_fill() #ending the filling
done()
Shape #4 - Equilateral Triangle
#!/usr/bin/python3
from turtle import *
color('#FFD445', '#3475a9')
goto(0,0) #turtle goes to (0,0) coordinate position
begin_fill() #begining of filling
for i in range(3):
forward(200)
left(120) #turn 120 degree to the left side
end_fill() #ending the filling
done()
Shape #5 - Polygon
#!/usr/bin/python3
from turtle import *
color('#FFD445', '#3475a9')
goto(0,0) #turtle goes to (0,0) coordinate position
begin_fill() #begining of filling
for i in range(6):
forward(200)
left(60) #turn 120 degree to the left side
end_fill() #ending the filling
done()
That's All for today !!
Comments
Post a Comment
Any Questions ? Leave a Comment