Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #IMPORTOWANIE BIBLIOTEKI
  2. import turtle
  3. import random
  4.  
  5. #KONFIGURUJE ZOLWIA
  6. stas = turtle.Turtle()
  7. stas.speed(0)
  8. stas.width(5)
  9. stas.shape("turtle")
  10. stas.color("indian red")
  11. stas.screen.setup(1280, 880)
  12. turtle.bgcolor("snow")
  13.  
  14. colors = ['red', 'blue', 'green', 'wheat']
  15.  
  16. def gora():
  17. if ( stas.ycor() < 400) :
  18. stas.setheading(90)
  19. stas.forward(100)
  20.  
  21. def dol():
  22. if ( stas.ycor() > -400 ) :
  23. stas.setheading(270)
  24. stas.forward(100)
  25.  
  26. def lewo():
  27. if (stas.xcor() > -600) :
  28. stas.setheading(180)
  29. stas.forward(100)
  30.  
  31. def prawo():
  32. if (stas.xcor() < 600) :
  33. stas.setheading(0)
  34. stas.forward(100)
  35.  
  36. def zmienKolor():
  37. stas.color(random.choice(colors))
  38.  
  39. def mazakWGore():
  40. stas.penup()
  41.  
  42. def mazakWDol():
  43. stas.pendown()
  44.  
  45. #czyszczenie planszy
  46. def wyczyscWszystko():
  47. stas.clear()
  48.  
  49.  
  50. #komenda powodujaca "nasluch" klawiatury
  51. turtle.listen()
  52.  
  53. turtle.onkey(gora, 'Up')
  54. turtle.onkey(dol, 'Down')
  55. turtle.onkey(prawo, 'Right')
  56. turtle.onkey(lewo, 'Left')
  57. turtle.onkey(zmienKolor, 'space')
  58. turtle.onkey(mazakWGore, 'g')
  59. turtle.onkey(mazakWDol, 'd')
  60. turtle.onkey(wyczyscWszystko, 'c')
  61.  
  62. #petla glowna programu
  63. turtle.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement