Download - Turtle Geometry the Python Way
![Page 1: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/1.jpg)
Turtle Geometry the Python Way
@SteveBattle
![Page 2: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/2.jpg)
Turtle Geometry“The tradition of calling our display creatures ‘turtles’ started with Grey Walter, a neurophysiologist who experimented in Britain… with tiny robot creatures he called ‘tortoises’. These inspired the first turtles designed at MIT.” (1980)
![Page 3: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/3.jpg)
Turtles and Tortoises“Not even Dr. Grey Walter, their creator, can say what these mechanical tortoises are going to do next.”
Bristol based Inventor of the first autonomous robots in 1948.
![Page 4: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/4.jpg)
BBC Buggy (1983)
The Buggy was tethered to the BBC Micro and used the ‘Logo’ language.
![Page 5: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/5.jpg)
The Python Way
Idle, use tabs not spaces
Start IDLE and start typing
![Page 6: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/6.jpg)
angles
The turtle starts off
facing this way
A right angle going clockwise
A 360˚ turn returns the turtle to 0˚
![Page 7: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/7.jpg)
sequenceCreate a new file (Python module)
Run
Save the file (but not as ‘turtle’)
![Page 8: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/8.jpg)
turtle functionsforward(length) backward(length)
left(angle) right(angle)
penup() pendown()
done()
speed(s) e.g. ‘slow’, ‘fast’, ‘fastest’
shape(name) e.g. ‘turtle’, ‘classic’
goto(x,y) x,y coordinates
![Page 9: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/9.jpg)
for loops
Everything inside the loop is indented. Use TAB not
SPACE
The loop repeats a fixed number
of times (4).
slow down the output
![Page 10: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/10.jpg)
defining functionsFunction definition
Call the function
Note the double indentation ‘turtle’ shape
![Page 11: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/11.jpg)
function parametersAdd parameter
‘length’
Call ‘square’ with argument
100
![Page 12: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/12.jpg)
polygonsComma
separated parameters
calculate angle and assign to a
variable
The output from ‘print’ appears in the IDLE console
The angles of a polygon sum to
360˚
![Page 13: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/13.jpg)
Interior & Exterior angles
The (interior) angles of a
triangle sum to only 180˚
The turtle turns through the
exterior angles, which sum to
360˚
![Page 14: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/14.jpg)
stars
What happens if we turn turtle
through a multiple of 360˚?
Try also heptagons: star(100,7,2)star(100,7,4)
Double the angle of a normal pentagon
![Page 15: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/15.jpg)
while loops
Try a non-integer multiple:
spiral(400, 3, 1.01, 10)
Exit the ‘while’ loop when the
condition is false.
‘goto’ these coordinates.
![Page 16: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/16.jpg)
recursion
Recursive functions call themselves.
The angle is close to 0 on the ‘straights’
We can also get spiral motion by increasing
the angle
![Page 17: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/17.jpg)
The Snowflake Curve
Every side has smaller sides and so on, ad
infinitum.
![Page 18: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/18.jpg)
conditionals test if we’ve bottomed out.
![Page 19: Turtle Geometry the Python Way](https://reader034.vdocument.in/reader034/viewer/2022052307/5538a06b4a79590a7f8b47a4/html5/thumbnails/19.jpg)