1. Intro to Turtle Graphics?
Turtle is like Logo, if you are familiar with logo then turtle in python is just a piece of cake for you, But if you are not familiar with the Logo it will be the best experience for you to explore turtle graphics in Python you will be really very happy that this course is only for beginners and anyone here can easily understand all the topics of turtle graphics here. We will study making some beautiful and colorful shapes using python and you will be really very happy that this course is only for beginners and anyone here can easily understand all the topics of turtle graphics. Here we will study making some beautiful and colorful shapes using python and you will really be liking it after studying some of the courses.
Not only turtle is for kids for drawing and making shapes but also turtle graphics in Python is used for making a graphical analog clock and too digital working clock it also lets you to be innovative and to draw really some beautiful shapes from it and one can easily learn turtle graphics without having much knowledge of python so let's start our course of turtle graphic at first we are going to make a simple turtle program...
2. Code of our first Turtle program
import turtle #At first we import module turtle
turtle.Screen() #it represents the turtle screen
don=turtle.Turtle() #we name the turtle as 'don' by writing the variable 'don' and then turtle.Turtle()
# turtle is the module.
# When a Turtle object is created or a function derived from some Turtle method is called a TurtleScreen object is automatically created.
# now our turtle name is don 'don: Turtle'
don.forward(100) # now our turtle name is "don"
# if we want our don (turtle) to move forward we can write "don.forward(100)"
# in the parenthesis we will write how much we want to move it forward as I have written 100.
3. Moving the turtle Right, Left
import turtle
turtle.Screen()
don=turtle.Turtle()
don.fd(100)#short form of forward
don.rt(100)
#we can also write right but rt is a short form of right.
#if we want our don (turtle) to move rt we can write "rt(100) "
# in the parenthesis we will write how much we want to tilt it in the right direction as I have written 100.
# so it will tilt till 100 by its right.
don.fd(100)
don.lt(100)
#we can also write left but lt is a short form of left.
#if we want our don (turtle) to move lt we can write "lt(100) "
# in the parenthesis we will write how much we want to tilt it by it's left like as I have written 100.
# so it will tilt till 100 by its lt.
don.fd(100)
4. Making a square
import turtle
turtle.Screen()
don=turtle.Turtle()
don.fd(100)
don.lt(90) #'don.lt(90)' it will tilt our turtle in the lt direction at a 90-degree angle means at a right angle
#we tilt it at 90 degrees because every angle of a square is a right angle.
don.fd(100)
don.lt(90)
don.fd(100)
don.lt(90)
don.fd(100)
5. Changing the Color of our turtle pen
import turtle
turtle.Screen()
don=turtle.Turtle()
don.color('red') #It changes the color of our turtle's pen.
don.fd(100)
don.lt(90)
don.fd(100)
don.lt(90)
don.fd(100)
don.lt(90)
don.fd(100)
6. Background color of our Turtle Screen
import turtle
win=turtle.Screen() #we represent 'win' variable as the turtle screen
win.bgcolor('red') #So now we can easily change the color of the 'win' turtle screen.
don=turtle.Turtle()
don.color('white')
don.fd(100)
7. Title of our turtle screen
import turtle
win=turtle.Screen() #we represent 'win' variable as the turtle screen
win.bgcolor('red') #So now we can easily change the color of the 'win' turtle screen.
win.title('hello') # we can change the title of our turtle screen like this.
don=turtle.Turtle()
don.color('white')
don.fd(100)
8. How to fill color to any shape?
import turtle
turtle.Screen()
don=turtle.Turtle()
don.fillcolor('red') # means has to fill with red color.
don.begin_fill() # this means to start \ begin filling color of the shape.
don.fd(100)
don.lt(90)
don.fd(100)
don.lt(90)
don.fd(100)
don.lt(90)
don.fd(100)
don.end_fill()# this means to end filling color.
10. Setting Background Image
import turtle
win=turtle.Screen()
win.bgpic('water.gif') #the image should be gif then only we can add our background image/pic.
#if your image is not gif go to paint and click on the file and click on open then find where is your image then click on open then go back again to file click " Save as > " then click Gif and save it with a new name.
11. Turtle Shape

import turtle
turtle.Screen()
don=turtle.Turtle()
don.shape('turtle') #it change the shape of the turtle we can write ('arrow','circle','turtle','square','triangle','classic')
don.fd(90)
don.fd(100)
12.Turtle Speed
import turtle
turtle.Screen()
don=turtle.Turtle()
don.shape('turtle')
don.speed(3) #speed of the turtle here is 3
don.fd(90)
don.speed(1) #speed of the turtle here is only 1
don.fd(100)
13. Permanent Shape
import turtle
turtle.Screen()
don=turtle.Turtle()
don.shape('turtle')
don.speed(3)
don.fd(90)
don.speed(1)
don.fd(100)
don.circle(100) #it draws a circle
14. Undo
import turtle
turtle.Screen()
don=turtle.Turtle()
don.fd(100)
don.fd(100)
don.undo()# it deletes (undo) what you have done lastly means it will erase that forwant the turtle had moved
don.rt(90)
don.fd(100)
15. Clear
import turtle
turtle.Screen()
don=turtle.Turtle()
don.fd(100)
don.fd(100)
don.undo()# it deletes (undo) what you have done lastly.
don.rt(90)
don.fd(100)
don.clear()# it erase(clear) the whole you have made.
don.fd(100)
don.fd(100)
16. Reset
import turtle
turtle.Screen()
don=turtle.Turtle()
don.fd(100)
don.fd(100)
don.undo()
don.rt(90)
don.fd(100)
don.clear()# it erase(clear) the whole you have made.
don.speed(1)
don.fd(100)
don.reset()#it backs to the starting turtle position.
don.fd(100)
don.fd(100)
17. Square in Square (while loop)
import turtle
n=200
win=turtle.Screen()
don=turtle.Turtle()
win.title('PRIYANSHI')
while n>0: #It will perform the function until the loop ended.
don.fd(n)
don.rt(90)
don.fd(n)
don.rt(90)
n=n-10
Hurray!!! We have finished Studying Turtle Now we can easily make simple as well as complex turtle programs.😇😇
Write in the comment your experience studying this lesson and don't forget to like and follow my blog.😊😊
Very nice presentation keep going...😊
ReplyDelete👍👍
ReplyDeleteThis is a very good article greatpython course
ReplyDelete