day 19 - turtles again T_T
This commit is contained in:
33
019/sandbox.py
Normal file
33
019/sandbox.py
Normal file
@ -0,0 +1,33 @@
|
||||
from turtle import Turtle, Screen
|
||||
|
||||
turtle = Turtle()
|
||||
screen = Screen()
|
||||
|
||||
def move_forward():
|
||||
turtle.forward(10)
|
||||
|
||||
def move_backward():
|
||||
turtle.backward(10)
|
||||
|
||||
def rotate_right():
|
||||
heading = turtle.heading() - 10
|
||||
turtle.setheading(heading)
|
||||
|
||||
def rotate_left():
|
||||
heading = turtle.heading() + 10
|
||||
turtle.setheading(heading)
|
||||
|
||||
def clear():
|
||||
turtle.clear()
|
||||
turtle.pu()
|
||||
turtle.home()
|
||||
turtle.pd()
|
||||
|
||||
|
||||
screen.listen()
|
||||
screen.onkey(move_forward, "Up")
|
||||
screen.onkey(move_backward, "Down")
|
||||
screen.onkey(rotate_left, "Left")
|
||||
screen.onkey(rotate_right, "Right")
|
||||
screen.onkey(clear, "c")
|
||||
screen.exitonclick()
|
||||
Reference in New Issue
Block a user