Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

Python With Turtle

dsfsdf

Uploaded by

santo nino
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Python With Turtle

dsfsdf

Uploaded by

santo nino
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Python with Turtle

By Sarah, Liana, and Vivian


What is Python with Turtle?
Python with Turtle is a Python library that enables
you to create virtual drawings and shapes. The
“turtle” is a the pen that you use to draw.
History

- Part of the original Logo programming language developed by


Wally Feurzig and Seymour Papert in 1966
- Turtles are a type of educational robots designed in the 1940s, that are typically
designed low to the ground. Some turtles are specifically designed to have pens
attached to the back of them so they can draw on large sheets of paper.
- It uses tkinter for the underlying graphics, it needs a version of
Python installed with Tk support.
https://repl.it/join/edvmqumf-

A Basic Program on Turtle


● There is no programming language called ‘turtle’, so we use Python whenever we import the turtle
library. Because of this, on our first line of code, we need to tell our computer we are using turtle:

>> import turtle

● Next, we need to name our turtle, and turtle will respond to whatever name you give it. We are just going to name it
“alfred”.

>> alfred = turtle.Turtle()

● After that, we can make alfred move forward, and we can do this by using the forward command in turtle. Whatever
number you put in the parentheses is how many pixels alfred will move forward.

>> alfred.forward(40)
https://repl.it/join/edvmqumf-

A Basic Program on Turtle (Part 2)


● Similarly, we can have alfred move backwards.

>> alfred.backward(40)

● We can also increase the speed of alfred by using the following command:

>> alfred.speed(100)

● Now, we want to be able to control alfred with the arrow keys, so we will put down the following
function to allow the screen to follow certain commands.
>> screen = turtle.Screen()
You can also give your screen
a different name
https://repl.it/join/edvmqumf-silverhailwolf

A Basic Program on Turtle (Part 3)


● Next, we need to create functions that are going to be in charge of alfred moving up, down, left, and
right.
>> def moveUp(): >> def moveRight():
alfred.setheading(90) alfred.setheading(0)
alfred.forward(50) alfred.forward(50)

>>def moveDown(): >> def moveLeft():


alfred.setheading(-90) alfred.setheading(180)
alfred.forward(50) alfred.forward(50)
https://repl.it/join/edvmqumf-silverhailwolf

A Basic Program on Turtle (Part 4)


● Now we need to make alfred move in each direction when the corresponding key is pressed, we can do
this by using the following commands that call the functions we made earlier:

>>screen.onkey(moveUp ,”Up”)

>>screen.onkey(moveDown, ”Down”)

>>screen.onkey(moveRight ,”Right”)

>>screen.onkey(moveLeft, ”Left”)

● Next, we need to make the Screen listen to the commands we are giving it
>>screen.listen()
Turtle Functions
- turtle.Turtle()
- Makes a Turtle - .color(string or int,int,int). - .fillcolor(string)
- turtle.Screen() - Changes Turtle Color - Sets to fill in something
- Makes a Screen - .penup(). drawn by the turtle with
- Enables the turtle to a color
- .forward(int)
move around without - .begin_fill().
- Moves Turtle Forward
drawing - Starting spot for filling color
- .backward(int)
- .pendown(). - .end_fill().
- Moves Turtle Backward
- Enables drawing - Ending spot for filling color
- .left(int)
- .pensize(int) - .xcor()
- Turns Turtle Left
- Changes Turtle Size - Find X coordinate of Turtle
- .right(int)
- .speed(int) - .ycor()
- Turns Turtle Right
- Changes Turtle Speed - Find Y coordinate of Turtle
- .shape(string).
- Changes Turtle Shape
MORE TURTLE FUNCTIONS:

Turtle Functions Continued


- .goto(int, int). - Returns distance between turtle and
- Moves Turtle to a - .position() given point or anothers turtle
specific Spot - Returns Turtle’s
position
- .circle(int)
- Draws a Circle - .towards(int, int)
- Returns the angle from
- .setheading(int)
the Turtle’s position to
- Set orientation of the
the position given
Turtle
- .heading()
- .home().
- Returns Turtle’s current
- Send Turtle to 0, 0
heading
and makes it go back
to its starting
- .distance(int, int or
orientation
turtle).
- .undo().
- Undo the Turtle last
actions
MORE TURTLE FUNCTIONS:
- .degrees(int)
- Set Number of
Degrees for a
Full Circle
- .radians()
- Set Angle
Measurement
Units to
Radians
- .isdown()
- Check to see if Pen is
Down or Up
- .reset().
- Delete All of
Turtle’s
Drawings, re-
center Turtle,
put
everything
back to
default
Interactive #1
https://repl.it/@silverhailwolf/FinalProjectFileA#main.py
Interactive #2
https: /repl.it/@silverhailwolf/FinalPr
ojectFileB#main.py
Resources
● (https://docs.python.org/3.3/library/turtle.html?highlight=turtle#:~:te
xt=Turtle%20graphics%20is%20a%20 popular,0)%20in%20the
%20 x%2Dy%20 plane.)
● Artemis Slides on Website:
http://www.bu.edu/lernet/artemis/lessons/Week3/Python%20with%20Turtle
2020.pdf
● https://docs.python.org/3/library/turtle.html#turtle.setheading
● MORE TURTLE FUNCTIONS: https://docs.python.org/3/library/turtle.html
Thanks for
listening!

You might also like