The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1
Chapter 5 Programming with Python 103

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


5 Figure 5-8: The turtle moves forward to draw a straight line


Switch back to the main Thonny window – if it’s hidden behind the Turtle Graphics window,
either click the minimize button on the Turtle Graphics window or click on the Thonny entry in the
task bar at the top of the screen – and click the Stop button to close the Turtle Graphics window.
Typing out every single movement instruction by hand would be tedious, so delete line 3 and
create a loop to do the hard work of creating shapes:


for i in range( 2 ):
pat.forward( 100 )
pat.right( 60 )
pat.forward( 100 )
pat.right( 120 )

Run your program, and Pat will draw a single parallelogram (Figure 5-9).

5 Figure 5-9: By combining turns and movements, you can draw shapes

Free download pdf