SDF -Week 10
SDF -Week 10
Note:
• Some of the slides of the course are based on the material provided
by the College of Technological Information, Zayed University, UAE.
• The copyrighted material belongs to their respective owners.
1
4/12/2024
Create a Turtle
• The use of turtle graphics is an interesting application of using loops.
Turtle Moves
import turtle # Allows us to use turtles
# Create Window
window = turtle.Screen() # Creates a playground for turtle
# Create Turtle
mat = turtle.Turtle()
mat.shape("turtle")
mat.color("blue")
# Move Turtle
mat.forward(50)
mat.left(90)
mat.forward(50)
mat.circle(50)
window.mainloop()
4
2
4/12/2024
Turtle Loops
import turtle
# Create Window
window = turtle.Screen()
# Create Turtle
sam = turtle.Turtle()
sam.shape("turtle")
# Loop Turtle
loopCount = 1
while loopCount <= 12:
sam.left(30) # Final moves
sam.forward(50) sam.backward(5)
sam.left(120) sam.left(90)
sam.forward(50) sam.forward(20)
loopCount=loopCount+1
window.mainloop()
3
4/12/2024
Turtle.pdf
Turtle Examples