t.forward python code example
Example 1: python turtle movement
import turtle
wn = turtle.Screen()
wn.setup(width=700,height=400)
wn.title("Python Turtle Movement")
def playerUp():
player.sety(player.ycor()+10)
def playerDown():
player.sety(player.ycor()-10)
def playerRight():
player.setx(player.xcor()+10)
def playerLeft():
player.setx(player.xcor()-10)
player = turtle.Turtle()
player.speed(0)
player.shape("square")
player.color("red")
player.penup()
player.goto(0,0)
wn.onkeypress(playerUp, "w")
wn.onkeypress(playerDown, "s")
wn.onkeypress(playerRight, "d")
wn.onkeypress(playerLeft, "a")
while True:
wn.update()
Example 2: turtle python
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
Example 3: how to hide turtle in python
>>> turtle.hideturtle()
Example 4: turtle module python
>>> player_one = turtle.Turtle()
>>> player_one.color("green")
>>> player_one.shape("turtle")
>>> player_one.penup()
>>> player_one.goto(-200,100)
>>> player_two = player_one.clone()
>>> player_two.color("blue")
>>> player_two.penup()
>>> player_two.goto(-200,-100)