Advertisement
Guest User

1

a guest
Mar 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. from tkinter import *
  2. from math import *
  3. import time
  4. root = Tk()
  5. canv = Canvas(root, height = 500, width = 500, bg = "light blue")
  6. canv.pack()
  7.  
  8. canv.create_line(300, 500, 300, 400, fill = 'orange', width = 5, tag = 'du')
  9.  
  10. def u_down(event):
  11. global angle,v
  12. angle += 0.05
  13. vx = v * cos(angle)
  14. vy = v * sin(angle)
  15. canv.delete('snr')
  16. canv.create_line(5,495,10*vx,495+10*vy,width=2,arrow=LAST,tag='snr')
  17.  
  18. def u_up(event):
  19. global angle,v
  20. angle -= 0.05
  21. vx = v * cos(angle)
  22. vy = v * sin(angle)
  23. canv.delete('snr')
  24. canv.create_line(5,495,10*vx,495+10*vy,width=2,arrow=LAST,tag='snr')
  25.  
  26. def u_right(event):
  27. global v
  28. v += 0.5
  29. vx = v * cos(angle)
  30. vy = v * sin(angle)
  31. canv.delete('snr')
  32. canv.create_line(5,495,10*vx,495+10*vy,width=2,arrow=LAST,tag='snr')
  33.  
  34. def u_left(event):
  35. global v
  36. v -= 0.5
  37. vx = v * cos(angle)
  38. vy = v * sin(angle)
  39. canv.delete('snr')
  40. canv.create_line(5,495,10*vx,495+10*vy,width=2,arrow=LAST,tag='snr')
  41.  
  42. def shot(event):
  43. global angle,x,y,v
  44. sx = x
  45. sy = y
  46. vx = v * cos(angle)
  47. vy = v * sin(angle)
  48. for i in range(100):
  49. sx += vx
  50. sy += vy
  51. vy += 0.3
  52. canv.delete('lo')
  53. canv.create_oval(sx,sy,sx+10,sy-10,fill = "blue",tag='lo')
  54. time.sleep(0.1)
  55. canv.update()
  56. if sx>=300 and sx<=300+vx and sy>=400-vy and sy<=500+vy:
  57. s = -1.1
  58. for i in range(10):
  59. s += 0.1
  60. canv.delete('du')
  61. canv.create_line(300, 500, 300+100*s**2, 400+100*(1-s**2), fill = 'orange', width = 5, tag = 'du')
  62. time.sleep(0.1)
  63. canvas.update()
  64. canv.create_text(300,300, text = 'ура', font = 'Arial')
  65.  
  66. root.bind("<Up>",u_up)
  67. root.bind("<Down>",u_down)
  68. root.bind("<Left>",u_left)
  69. root.bind("<Right>",u_right)
  70. root.bind("<space>",shot)
  71.  
  72. angle = -1
  73. angle1 = str(-1*((180/pi)*angle))
  74. v = 5
  75. vx = v * cos(angle)
  76. vy = v * sin(angle)
  77. canv.create_line(5,495,10*vx,495+10*vy,width=2,arrow=LAST,tag='s1')
  78. x, y = 0, 500
  79. bullet = canv.create_oval(x+10,y,x,y-10,fill = "blue",tag='s2')
  80. canv.create_text(35, 40, text = str(v), font = 'Arial')
  81. canv.create_text(20, 40, text = 'V = ', font = 'Arial')
  82. canv.create_text(100, 60, text = str(angle1), font = 'Arial')
  83. canv.create_text(20, 60, text = 'a = ', font = 'Arial')
  84. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement