Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import tkinter
  2. import random
  3. canvas=tkinter.Canvas(width=640, height=480, bg='green')
  4. canvas.pack()
  5.  
  6. riadkov=48
  7. cesta=[270]*riadkov
  8.  
  9. def kresli_cestu():
  10. canvas.delete('cesta')
  11. for i in range(riadkov):
  12. canvas.create_rectangle(cesta[i],i*10,cesta[i]+100,i*10+10, fill='white', outline='', tags='cesta')
  13.  
  14.  
  15. def kresli_auto():
  16. canvas.delete('auto')
  17. canvas.create_rectangle(autox,autoy,autox+10,autoy+10, fill='red', tags='auto')
  18.  
  19. def vlavo(klaves):
  20. global autox
  21. autox-=10
  22.  
  23. def vpravo(klave):
  24. global autox
  25. autox+=10
  26.  
  27. def animacia():
  28. posun_cestu()
  29. kresli_cestu()
  30. kresli_auto()
  31. canvas.after(100, animacia)
  32.  
  33. def posun_cestu():
  34. novy=cesta[0]+random.randrange(-1,2)*10
  35. if novy<0:
  36. novy=0
  37. if novy>540:
  38. novy=540
  39. cesta.insert(0, novy)
  40. cesta.pop()
  41.  
  42.  
  43.  
  44. kresli_cestu()
  45. autox=320
  46. autoy=460
  47.  
  48. kresli_auto()
  49. animacia()
  50. canvas.bind_all('<Left>',vlavo)
  51. canvas.bind_all('<Right>',vpravo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement