Python With Turtle
Python With 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”.
● 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-
>> 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
>>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: