Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agent P, I have been hearing some rumours about a Python Turtle.

Similar presentations


Presentation on theme: "Agent P, I have been hearing some rumours about a Python Turtle."— Presentation transcript:

1 Agent P, I have been hearing some rumours about a Python Turtle.
Please find it and invite it to join O.W.A.C.A.! Aims: For students to gain some experience wth Python's turtle module. Objectives: ALL: Use the turtle module in the interpreter. MOST: Experiment with simple drawings using turtle. SOME: Make simple programs using the turtle module and explore some of its more advanced features.

2 Have a go at using these basic commands.
First we create an instance of the Turtle class. I called it 'a', you can call it what you like. Then we can use the dot notation to invoke the turtle's methods. a.fd(n) -> go forward n pixels. a.lt(n) -> turn left n degrees. a.color(n) -> change the color of the line. a.home() -> go back to 0,0. a.pensize(n) -> change the width of the line. a.up() -> take the pen off the paper.

3 Have a play with the turtle object.
Can you work out how to ... ? -> turn right -> go back -> put the pen down again Mini Tasks In the interpreter: -> draw a triangle -> draw a pentagon -> draw a circle (don't use the built-in method). If you have used Scratch, the turtle module may seem familiar to you. They are both descended from the LOGO programming language.

4 The center of the turtle's window is 0,0.
You can use the “goto” method to move the turtle to a position on the screen by its co-ordinates. The center of the turtle's window is 0,0. You can write words in the turtle window. You can also change the turtle to a turtle shape and stamp an imprint on the screen. If you type the name of your turtle object and a dot, IDLE will show you a list of methods that you could invoke. Have a play and find out what some of them do.

5 If you succeeded with the triangle and pentagon scripts, you probably noticed that you could generalise the procedure. And a circle is just a polygon with very many sides ....

6 I asked the program to draw a polygon with 360 sides, all of length 1.
Task: For the next activity, we need a function that will draw a quarter of a circle. See if you can work this out for yourself. If you can, I want something that will draw this shape. It is just two quarter-circles facing one another.

7 Turtle Challenge Once you have the “petal” shape function, you should be able to write a program that draws flowers like this. Choose some nice colours and vary the number of “petals” in the flower until you find a design that you like.

8 Only if you are stuck ... Here's a possible quarter-circle function. circumference = π * 2 * radius We are going to draw the arc in steps corresponding to one degree. Let's call the length of these “step”. step = (π * 2 * radius) / 360 step = For my version, I decided that 0.02 was close enough.

9 Using fill Just use begin_fill() before you start drawing the shape you want to fill. Then, use end_fill() and the shape will be filled for you.

10 Task: Have a play with that filled square routine. If you alter the amount of turn you can write a function that produces results similar to these. You'll probably want to use a while loop. How will your program know when it is time to stop?


Download ppt "Agent P, I have been hearing some rumours about a Python Turtle."

Similar presentations


Ads by Google