Guest User

Untitled

a guest
Jan 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. from math import *
  2. from tkinter import *
  3.  
  4. # root params:
  5. root = Tk()
  6. width = 1000
  7. height = 700
  8.  
  9. canv = Canvas(root, width=width, height=height, bg='white')
  10.  
  11. # canvas coords creating flag
  12. flag = False
  13.  
  14. # canvas coords lines |__
  15. def create_coords(canv):
  16. canv.create_line(6, 497, 6, 6, width=3, arrow=LAST) # Y (+6, -3, +6, +6)
  17. canv.create_line(6, 497, 997, 497, width=3, arrow=LAST) # X (+6, -3, -3, -3)
  18.  
  19. # canvas create entrys:
  20. def create_interface(canv, root):
  21. entry_u0 = Entry(canv)
  22. canv.create_window(250, 550, window=entry_u0, height=25, width=250)
  23. canv.create_text(100, 550, fill="darkblue", font="Helvectica", text="u0=")
  24. entry_m = Entry(canv)
  25. canv.create_window(250, 600, window=entry_m, height=25, width=250)
  26. canv.create_text(100, 600, fill="darkblue", font="Helvectica", text="m=")
  27. entry_a = Entry(canv)
  28. canv.create_window(250, 650, window=entry_a, height=25, width=250)
  29. canv.create_text(100, 650, fill="darkblue", font="Helvectica", text="a=")
  30. canv.create_text(250, 515, fill="darkblue", font="Helvectica", text="Input data")
  31. button1 = Button(text="Create graphics", command=lambda: create_graphics(canv, entry_u0, entry_m, entry_a), anchor=W)
  32. button1.configure(width=20, activebackground="gray", relief=FLAT, borderwidth=4, highlightbackground='black')
  33. button1_window = canv.create_window(400, 530, anchor=NW, window=button1)
  34. button2 = Button(text="Quit", command=root.quit, anchor=W)
  35. button2.configure(width=20, activebackground="gray", relief=FLAT, borderwidth=4, highlightbackground='black')
  36. button2_window = canv.create_window(400, 560, anchor=NW, window=button2)
  37. #canv.bind("<Return>", lambda event: create_graphics(canv, entry_u0, entry_m, entry_a))
  38.  
  39. # buttons methods:
  40. def create_graphics(canv, entry_u0, entry_m, entry_a):
  41. global flag
  42. # input params
  43. a = int(entry_a.get())
  44. m = float(entry_m.get())
  45. U0 = float(entry_u0.get())
  46. # all_consts
  47. x0 = 53
  48. y0 = -50
  49. # U0 = 100
  50. # a = 30
  51. sin_a = sin(a / 180 * 3.14)
  52. cos_a = cos(a / 180 * 3.14)
  53. g = 9.8
  54. # 1_consts
  55. Ux1 = U0 * cos_a
  56. Uy1 = U0 * sin_a
  57. y1 = 0
  58. x1 = 0
  59. # 2_consts
  60. k1 = 0.034306
  61. k2 = 0.008105
  62. m = 1 # r, p
  63. Ux2 = U0 * cos_a
  64. Uy2 = U0 * sin_a
  65. y2 = 0
  66. x2 = 0
  67. # loop counts:
  68. count = 16000
  69. count_percent_if = 16000 % 800
  70. count_percent_k = 1000
  71. canv.create_oval(x0, y0, x0 + 1, y0 + 1, fill='black')
  72.  
  73. # test 2 consts
  74. u0x = U0 * cos_a
  75. u0y = U0 * sin_a
  76. uxi = u0x
  77. uyi = u0y
  78.  
  79. uxi1 = uxi - (k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uxi / m
  80. uyi1 = uyi - ((k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uyi + m * g) / m
  81. x0 = 0
  82. y0 = 0
  83. xi = x0
  84. yi = y0
  85. for i in range(0, 16000):
  86. # creating coords_lines for graphic:
  87. if i % 800 == 0 and flag == False:
  88. k = (1 / 16) * i - 500
  89. if k + 500 + 4 > 10:
  90. canv.create_line(k + 500 + 3, 499, 500 + k + 3, 490, width=1, fill='black') # x line1 (+3, -1, +3, -10)
  91. canv.create_line(k + 500 + 3, 470, 500 + k + 3, 6, width=0.5, fill='gray') # x line2 (+4, -30, +4, +6)
  92. canv.create_text(k + 507, 500 - 17, text=str(k + 500 - 50), fill='black',
  93. font=('Helvectica', '10')) # x number
  94. if k != 0 and k + 500 < 500:
  95. canv.create_line(0, k + 500, 10, k + 500, width=1, fill='black') # y line 1 (0, 0, +10, 0)
  96. canv.create_line(50, k + 500, 994, k + 500, width=0.5, fill='gray') # y line 2 (50, 0, -6, 0)
  97. if k + 500 > 30:
  98. canv.create_text(28, k + 500, text=str(abs(k) - 50), fill='black',
  99. font=('Helvectica', '10')) # y number
  100.  
  101. # for first graphic:
  102. x1 = Ux1*i/16*cos_a
  103. y1 = (U0 * sin_a-g*i/16)*i/16 - g * (i / 16) ** 2 / 2 -50
  104. xi1 = xi + abs(uxi)
  105. yi1 = yi + uyi
  106. if yi >= 0 :
  107. canv.create_line(xi+53, 500-yi-50, xi1+53, 500-yi1-50, fill='red') # oval second graphic
  108. # todo +x0, 500-y0
  109. #todo create this->
  110. # for second graphic:
  111. uxi1 = uxi - (k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uxi / m
  112. uyi1 = uyi - ((k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uyi + m * g) / m
  113.  
  114. print(yi)
  115.  
  116. xi = xi1
  117. yi = yi1
  118. uxi = uxi1
  119. uyi = uyi1
  120.  
  121. # for graphics only on y>0 creating <= y_max = 450-1
  122.  
  123. #if 500-y1 <= 449:
  124. #canv.create_oval(i/16+53, 500-y1, i/16+1+53, 500-y1 + 1, fill='blue', outline='blue') # oval first graphic
  125.  
  126.  
  127.  
  128. flag = True
  129.  
  130. # creating
  131. create_coords(canv)
  132. create_interface(canv, root)
  133.  
  134. # main rooting, canv packaging
  135. canv.pack()
  136. root.mainloop()
Add Comment
Please, Sign In to add comment