-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.python
More file actions
executable file
·84 lines (66 loc) · 2.68 KB
/
tempCodeRunnerFile.python
File metadata and controls
executable file
·84 lines (66 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
def compute_zn(n):
"""Calcule les points zn avec z0 = 16 et zn+1 = ((1+i)/2)zn"""
if n == 0:
return [16 + 0j] # z0 = 16
prev_z = compute_zn(n-1)[-1]
multiplier = (1 + 1j) / 2 # Le nombre complexe (1+i)/2
zn = multiplier * prev_z
return compute_zn(n-1) + [zn]
def create_animation():
# Configuration de la figure
fig, ax = plt.subplots(figsize=(12, 12))
ax.set_xlabel('Re(z)')
ax.set_ylabel('Im(z)')
ax.set_title('Construction des points zn et lignes Ln')
# Points et lignes à animer
points, = ax.plot([], [], 'bo', label='Points zn')
line, = ax.plot([], [], 'r-', label='Ligne Ln')
# Ajout des axes
ax.axhline(y=0, color='k', linestyle='-', alpha=0.3)
ax.axvline(x=0, color='k', linestyle='-', alpha=0.3)
ax.grid(True, alpha=0.3)
ax.set_aspect('equal')
ax.legend()
# Pré-calcul de tous les points
all_zn = compute_zn(20) # On calcule jusqu'à z20
# Calcul des limites du graphique basé sur les points
max_coord = max([max(abs(z.real), abs(z.imag)) for z in all_zn])
margin = max_coord * 0.1
ax.set_xlim(-max_coord - margin, max_coord + margin)
ax.set_ylim(-max_coord - margin, max_coord + margin)
def init():
points.set_data([], [])
line.set_data([], [])
return points, line
def animate(frame):
ax.cla() # Clear les annotations précédentes
ax.grid(True, alpha=0.3)
ax.set_aspect('equal')
ax.set_xlim(-max_coord - margin, max_coord + margin)
ax.set_ylim(-max_coord - margin, max_coord + margin)
ax.set_xlabel('Re(z)')
ax.set_ylabel('Im(z)')
n = frame # Commencer avec n=0
current_points = all_zn[:n+1]
# Conversion des nombres complexes en coordonnées x,y
x_coords = [z.real for z in current_points]
y_coords = [z.imag for z in current_points]
# Annotations des points
for i, (x, y) in enumerate(zip(x_coords, y_coords)):
ax.annotate(f'z{i}\n({x:.2f}, {y:.2f}i)', (x, y),
xytext=(10, 10), textcoords='offset points',
fontsize=8)
ax.plot(x_coords, y_coords, 'bo-', label='Points et ligne Ln')
ax.set_title(f'Construction jusqu\'à z{n}')
ax.legend()
return []
# Création de l'animation
anim = FuncAnimation(fig, animate, init_func=init, frames=21,
interval=1000, repeat=True)
plt.show()
return anim
if __name__ == "__main__":
animation = create_animation()