Skip to content

Commit 85c64d0

Browse files
committed
animation hyperbole
1 parent 7d31351 commit 85c64d0

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

intersection_cercle/intersection_cercle.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def save_as_png(canvas: Canvas):
6060

6161
def make_animation(canvas: Canvas):
6262
if hasattr(canvas, "frame_number"):
63-
cmd = ["magick", "-delay", "20", "-loop", "0"]
63+
cmd = ["magick", "-delay", "10", "-loop", "0"]
6464
frames = []
6565
frames.extend(f"frame{i}.png" for i in range(canvas.frame_number))
6666
cmd.extend(frames)
@@ -77,6 +77,7 @@ def key_callback(root: Tk, canvas: Canvas, event: Event):
7777
root.quit()
7878
elif event.keysym == "s":
7979
make_animation(canvas)
80+
root.quit()
8081
else:
8182
print(f"évenement inconnu: {event}")
8283

@@ -244,43 +245,47 @@ def droite(x: complex, p: float) -> complex:
244245

245246

246247
cA, cB = None, None
248+
dot_radius = 0.1 if args.save else 0.03
247249

248250

249-
def intersect(r, d):
251+
def intersect(r, d, min_r):
250252
global cA, cB
251253

252254
P, Q = circle_intersect(A, r, B, r + d)
253255
if not P:
254256
return
255257

256-
if cA:
257-
canvas.delete(cA)
258-
if cB:
259-
canvas.delete(cB)
258+
if d > 0:
259+
if cA:
260+
canvas.delete(cA)
261+
if cB:
262+
canvas.delete(cB)
260263

261-
cA = circle(A, r, outline="red")
262-
cB = circle(B, r + d, outline="red")
264+
cA = circle(A, r, outline="red")
265+
cB = circle(B, r + d, outline="red")
263266

264-
circle(P, 0.05, fill="white")
265-
circle(Q, 0.05, fill="white")
267+
circle(P, dot_radius, fill="white")
268+
circle(Q, dot_radius, fill="white")
266269

267270
save_as_png(canvas)
268271

269-
if r > 0:
270-
# rend l'animation plus fluide
271-
if r > 2:
272-
e = 0.2
273-
elif r > 0.75:
274-
e = 0.05
275-
else:
276-
e = 0.01
272+
# rend l'animation plus fluide
273+
if r - min_r > 2:
274+
e = 0.2
275+
elif r - min_r > 1:
276+
e = 0.1
277+
elif r - min_r > 0.1:
278+
e = 0.05
279+
else:
280+
e = 0.01
281+
r -= e
277282

278-
# e = 0.01 * r
279-
root.after(2, lambda: intersect(r - e, d))
283+
if r > 0:
284+
root.after(20, lambda: intersect(r, d, min_r))
280285

281286

282287
root.title("Construction par ensemble de points d'une hyperbole")
283-
intersect(12, d)
284-
# intersect(12, -d)
288+
intersect(12, d, c - a)
289+
intersect(12 + d, -d, c + a)
285290

286291
root.mainloop()

0 commit comments

Comments
 (0)