Want to create interactive content? It’s easy in Genially!
PYTHON TURTLE MODULE
Tempa Rinchen
Created on September 11, 2022
Start designing with a free template
Discover more than 1500 professional designs like these:
Transcript
PYTHON
Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems
definition from coursera
02.Customizing Turtle Window
01.cREATING TURTLE WINDOW
PYTHON TURTLE GRAPHICS
03.moving turtle and pen size
04.Color control and color fill
06. fOR LOOPS AND WHILE LOOPS
05. DEFINING FUNCTION
08. COMING SOON
07. COMMING SOON
11.COMING SOON
10. COMING SOON
12. COMING SOON
09. COMING SOON
01
python idle and creating turtle window
We use python IDLE to write,edit and execute python programs To open python IDLE you can press windows button on your keyboard and type in idle and then hit enter.
Example video to open python idle
home
02
custmizing tURTLE wINDOW
step 1 : To load turtle module in python idle shell, type import turtle Hint 2: Type _____________= turtle.Turtle( ) to open turtle window example: tempa = turtle.Turtle () or rinchen = turtle.Turtle() You can change the background color of your turtle window screen by typing the object name.screen.bgcolor("any color") To change the color of the turtle : object name.color("any color") To hide turtle: objectname.hideturtle() To insert a new background picture: objectname.screen.bgpic("pic name") To change the shape of the turtle : objectname.shape("shape name") To change head direction of the turtle: objectname.setheading(angle)
2.1
Individual Activity
Instruction: 1. Open a new python file and then load the turtle module. 2. Open a new turtle window and then hide the turtle. 3. Change the background color of the turtle window to any color of your choice 4. Load an image of a tree inside the turtle window.
Moving turtle and pen size
***When the turtle moves, it creates a line along its way*** 1. To move your turtle Forward: turtle name.forward(no of steps) example: karma.forward(100) or karma.fd(100) 2. To move your turtle Backward: turtle name.backward(no of steps) example: karma.backward(300) To change direction of the turtle: 1. turtle name.setheading (angle of the turtle direction) example: t.setheading(45)
3.1
Individual Activity
Instruction 1. Write a code in a python file to draw a perfect square and a rectangle in different location of the screen
3.2
Moving turtle and pen size contd
To lift your turtle: turtle name.penup() To put down your pen: turtle name.pendown() To move your turtle in different point: turtlename.goto(coordinates) To change your drawing speed: turtlename.speed(speed value) [0 is highest] you can use forloop to shorten your code to draw different shape for i in range(no of loop to be repeated): example to draw a square, number of times the loop should repeat is 4, so the forloop code should be :- for i in range(4) turtlename.fd(no of steps) turtlename.left(angle)
cOLOR CONTROL AND color FILL
To change the pen color of your turtle: turtlename.pencolor("color") To change the pen size of your turtle: turtle.pensize(value) To fill the shape, first you have to list the color : turtle.fillcolor("color") Then write begin_fill function: turtlename.begin_fill() Then draw the shape : turtlename.circle(50) and finally use end_fill function: turtlename.end_fill()
Individual activityL
Draw any 3 diffeent shape in different location and fill it with different color
Defining function
Define a function First of all we need to define the function. A function definition consists of: the keyword (which means definition)def the name of the function of parentheses () colon : of the body of the function containing the code. Here is, for example, the definition of the triangle function:
Example Defining function
def triangle(): forward(100) left(120) forward(100) left(120) forward(100) left(120) forward(100)
Project on python turtle
link 2: https://www.geeksforgeeks.org/turtle-programming-python/ link 1: https://realpython.com/beginners-guide-python-turtle/