Advertisement
humpda

TurtleMove

Sep 9th, 2019
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import turtle
  2.  
  3. screen = turtle.Screen()
  4.  
  5. # this assures that the size of the screen will always be 400x400 ...
  6. screen.setup(400, 400)
  7.  
  8. move_speed = 10
  9. turn_speed = 10
  10.  
  11. # these defs control the movement of our "turtle"
  12. def forward():
  13.   turtle.forward(move_speed)
  14.  
  15. def backward():
  16.   turtle.backward(move_speed)
  17.  
  18. def left():
  19.   turtle.left(turn_speed)
  20.  
  21. def right():
  22.   turtle.right(turn_speed)
  23.  
  24. turtle.pendown()
  25. turtle.speed(0)
  26. turtle.home()
  27.  
  28. # now associate the defs from above with certain keyboard events
  29. screen.onkey(forward, "Up")
  30. screen.onkey(backward, "Down")
  31. screen.onkey(left, "Left")
  32. screen.onkey(right, "Right")
  33. screen.listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement