Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7011d1c

Browse files
author
Jirka Hladky
committed
Clear trace history when animation get restarted
1 parent b111729 commit 7011d1c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

examples/animation/double_pendulum.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
G = 9.8 # acceleration due to gravity, in m/s^2
2020
L1 = 1.0 # length of pendulum 1 in m
2121
L2 = 1.0 # length of pendulum 2 in m
22+
L = L1 + L2 # maximal length of the combined pendulum
2223
M1 = 1.0 # mass of pendulum 1 in kg
2324
M2 = 1.0 # mass of pendulum 2 in kg
24-
t_stop = 50 # how many seconds to simulate
25+
t_stop = 5 # how many seconds to simulate
2526
history_len = 500 # how many trajectory points to display
2627

2728

@@ -73,9 +74,7 @@ def derivs(state, t):
7374
y2 = -L2*cos(y[:, 2]) + y1
7475

7576
fig = plt.figure(figsize=(5, 4))
76-
ax = fig.add_subplot(autoscale_on=False,
77-
xlim=(-(L1+L2), (L1+L2)),
78-
ylim=(-(L1+L2), 1.))
77+
ax = fig.add_subplot(autoscale_on=False, xlim=(-L, L), ylim=(-L, 1.))
7978
ax.set_aspect('equal')
8079
ax.grid()
8180

@@ -90,6 +89,10 @@ def animate(i):
9089
thisx = [0, x1[i], x2[i]]
9190
thisy = [0, y1[i], y2[i]]
9291

92+
if i == 0:
93+
history_x.clear()
94+
history_y.clear()
95+
9396
history_x.appendleft(thisx[2])
9497
history_y.appendleft(thisy[2])
9598

0 commit comments

Comments
 (0)