Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- from tkinter import *
- # root params:
- root = Tk()
- width = 1000
- height = 700
- canv = Canvas(root, width=width, height=height, bg='white')
- # canvas coords creating flag
- flag = False
- # canvas coords lines |__
- def create_coords(canv):
- canv.create_line(6, 497, 6, 6, width=3, arrow=LAST) # Y (+6, -3, +6, +6)
- canv.create_line(6, 497, 997, 497, width=3, arrow=LAST) # X (+6, -3, -3, -3)
- # canvas create entrys:
- def create_interface(canv, root):
- entry_u0 = Entry(canv)
- canv.create_window(250, 550, window=entry_u0, height=25, width=250)
- canv.create_text(100, 550, fill="darkblue", font="Helvectica", text="u0=")
- entry_m = Entry(canv)
- canv.create_window(250, 600, window=entry_m, height=25, width=250)
- canv.create_text(100, 600, fill="darkblue", font="Helvectica", text="m=")
- entry_a = Entry(canv)
- canv.create_window(250, 650, window=entry_a, height=25, width=250)
- canv.create_text(100, 650, fill="darkblue", font="Helvectica", text="a=")
- canv.create_text(250, 515, fill="darkblue", font="Helvectica", text="Input data")
- button1 = Button(text="Create graphics", command=lambda: create_graphics(canv, entry_u0, entry_m, entry_a), anchor=W)
- button1.configure(width=20, activebackground="gray", relief=FLAT, borderwidth=4, highlightbackground='black')
- button1_window = canv.create_window(400, 530, anchor=NW, window=button1)
- button2 = Button(text="Quit", command=root.quit, anchor=W)
- button2.configure(width=20, activebackground="gray", relief=FLAT, borderwidth=4, highlightbackground='black')
- button2_window = canv.create_window(400, 560, anchor=NW, window=button2)
- #canv.bind("<Return>", lambda event: create_graphics(canv, entry_u0, entry_m, entry_a))
- # buttons methods:
- def create_graphics(canv, entry_u0, entry_m, entry_a):
- global flag
- # input params
- a = int(entry_a.get())
- m = float(entry_m.get())
- U0 = float(entry_u0.get())
- # all_consts
- x0 = 53
- y0 = -50
- # U0 = 100
- # a = 30
- sin_a = sin(a / 180 * 3.14)
- cos_a = cos(a / 180 * 3.14)
- g = 9.8
- # 1_consts
- Ux1 = U0 * cos_a
- Uy1 = U0 * sin_a
- y1 = 0
- x1 = 0
- # 2_consts
- k1 = 0.034306
- k2 = 0.008105
- m = 1 # r, p
- Ux2 = U0 * cos_a
- Uy2 = U0 * sin_a
- y2 = 0
- x2 = 0
- # loop counts:
- count = 16000
- count_percent_if = 16000 % 800
- count_percent_k = 1000
- canv.create_oval(x0, y0, x0 + 1, y0 + 1, fill='black')
- # test 2 consts
- u0x = U0 * cos_a
- u0y = U0 * sin_a
- uxi = u0x
- uyi = u0y
- uxi1 = uxi - (k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uxi / m
- uyi1 = uyi - ((k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uyi + m * g) / m
- x0 = 0
- y0 = 0
- xi = x0
- yi = y0
- for i in range(0, 16000):
- # creating coords_lines for graphic:
- if i % 800 == 0 and flag == False:
- k = (1 / 16) * i - 500
- if k + 500 + 4 > 10:
- canv.create_line(k + 500 + 3, 499, 500 + k + 3, 490, width=1, fill='black') # x line1 (+3, -1, +3, -10)
- canv.create_line(k + 500 + 3, 470, 500 + k + 3, 6, width=0.5, fill='gray') # x line2 (+4, -30, +4, +6)
- canv.create_text(k + 507, 500 - 17, text=str(k + 500 - 50), fill='black',
- font=('Helvectica', '10')) # x number
- if k != 0 and k + 500 < 500:
- canv.create_line(0, k + 500, 10, k + 500, width=1, fill='black') # y line 1 (0, 0, +10, 0)
- canv.create_line(50, k + 500, 994, k + 500, width=0.5, fill='gray') # y line 2 (50, 0, -6, 0)
- if k + 500 > 30:
- canv.create_text(28, k + 500, text=str(abs(k) - 50), fill='black',
- font=('Helvectica', '10')) # y number
- # for first graphic:
- x1 = Ux1*i/16*cos_a
- y1 = (U0 * sin_a-g*i/16)*i/16 - g * (i / 16) ** 2 / 2 -50
- xi1 = xi + abs(uxi)
- yi1 = yi + uyi
- if yi >= 0 :
- canv.create_line(xi+53, 500-yi-50, xi1+53, 500-yi1-50, fill='red') # oval second graphic
- # todo +x0, 500-y0
- #todo create this->
- # for second graphic:
- uxi1 = uxi - (k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uxi / m
- uyi1 = uyi - ((k1 + k2 * sqrt(uxi ** 2 + uyi ** 2)) * uyi + m * g) / m
- print(yi)
- xi = xi1
- yi = yi1
- uxi = uxi1
- uyi = uyi1
- # for graphics only on y>0 creating <= y_max = 450-1
- #if 500-y1 <= 449:
- #canv.create_oval(i/16+53, 500-y1, i/16+1+53, 500-y1 + 1, fill='blue', outline='blue') # oval first graphic
- flag = True
- # creating
- create_coords(canv)
- create_interface(canv, root)
- # main rooting, canv packaging
- canv.pack()
- root.mainloop()
Add Comment
Please, Sign In to add comment