Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- line1 = canvas.create_line(250, 200, 350, 200, width=3)
- line2 = canvas.create_line(300, 150, 300, 250, width=3)
- Помпа 1
- def animate(angle):
- x1, y1, x2, y2 = canvas.coords(line1)
- cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
- new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
- new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
- new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
- new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
- canvas.coords(line1, new_x1, new_y1, new_x2, new_y2)
- x1, y1, x2, y2 = canvas.coords(line2)
- cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
- new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
- new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
- new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
- new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
- canvas.coords(line2, new_x1, new_y1, new_x2, new_y2)
- if animating:
- canvas.after(10, animate, angle + 0.1)
- animating = False
- def start_animation():
- global animating
- if not animating:
- animating = True
- animate(0)
- def stop_animation():
- global animating
- animating = False
- button_start = tk.Button(root, text="Start", command=start_animation)
- button_start.pack()
- button_stop = tk.Button(root, text="Stop", command=stop_animation)
- button_stop.pack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement