ABIX_Edukacja

Space_Turtle

Nov 25th, 2019
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. # Click in the righthand window to make it active then use your arrow
  2. # keys to control the spaceship!
  3. import turtle
  4.  
  5. screen = turtle.Screen()
  6.  
  7. # this assures that the size of the screen will always be 400x400 ...
  8. screen.setup(400, 400)
  9.  
  10. # ... which is the same size as our image
  11. # now set the background to our space image
  12. # https://www.jpl.nasa.gov/spaceimages/details.php?id=pia14417
  13. # must be converted to PNG file
  14. screen.bgpic("space.png")
  15.  
  16. # Or, set the shape of a turtle
  17. # https://www.flaticon.com/free-icon/rocket_201901
  18. screen.addshape("rocket.gif")
  19. turtle.shape("rocket.gif")
  20.  
  21. move_speed = 10
  22. turn_speed = 20
  23.  
  24. # these defs control the movement of our "turtle"
  25. def forward():
  26.   turtle.forward(move_speed)
  27.  
  28. def backward():
  29.   turtle.backward(move_speed)
  30.  
  31. def left():
  32.   turtle.left(turn_speed)
  33.  
  34. def right():
  35.   turtle.right(turn_speed)
  36.   turtle.update()
  37.  
  38. turtle.penup()
  39. turtle.speed(10)
  40. turtle.home()
  41.  
  42. # now associate the defs from above with certain keyboard events
  43. screen.onkey(forward, "Up")
  44. screen.onkey(backward, "Down")
  45. screen.onkey(left, "Left")
  46. screen.onkey(right, "Right")
  47. screen.listen()
Advertisement
Add Comment
Please, Sign In to add comment