Advertisement
Vasilena

PUMPS

Apr 20th, 2023 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. line1 = canvas.create_line(250, 200, 350, 200, width=3)
  2. line2 = canvas.create_line(300, 150, 300, 250, width=3)
  3.  
  4. Помпа 1
  5.  
  6. def animate(angle):
  7. x1, y1, x2, y2 = canvas.coords(line1)
  8. cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
  9. new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
  10. new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
  11. new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
  12. new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
  13. canvas.coords(line1, new_x1, new_y1, new_x2, new_y2)
  14.  
  15. x1, y1, x2, y2 = canvas.coords(line2)
  16. cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
  17. new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
  18. new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
  19. new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
  20. new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
  21. canvas.coords(line2, new_x1, new_y1, new_x2, new_y2)
  22.  
  23. if animating:
  24. canvas.after(10, animate, angle + 0.1)
  25.  
  26.  
  27. animating = False
  28.  
  29.  
  30. def start_animation():
  31. global animating
  32. if not animating:
  33. animating = True
  34. animate(0)
  35.  
  36.  
  37. def stop_animation():
  38. global animating
  39. animating = False
  40.  
  41.  
  42. button_start = tk.Button(root, text="Start", command=start_animation)
  43. button_start.pack()
  44.  
  45. button_stop = tk.Button(root, text="Stop", command=stop_animation)
  46. button_stop.pack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement