-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg_anim_test.py
132 lines (99 loc) · 3.97 KB
/
bg_anim_test.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import numpy as np
import matplotlib.pyplot as plt
from time import time
import matplotlib.animation as animation
import bga_4_0 as bga
import manifold_reflected_brownian_motion as mrbm
bga = reload(bga)
mrbm = reload(mrbm)
def face_position(bg_int, face_num, faces, dim=3):
"""Return the current and last positions in the desired dimensions for viewing."""
x_list = []
y_list = []
## Right now, only views in x and y dimensions
for v in faces[face_num]:
x_list.append(bg_int.x[dim*v])
y_list.append(bg_int.x[dim*v + 1])
x_list.append(bg_int.x[dim*faces[face_num][0]])
y_list.append(bg_int.x[dim*faces[face_num][0] + 1])
return (np.array(x_list), np.array(y_list))
def init_aux(face_lines):
"""initialize animation"""
#face_lines = ()
for k, f in enumerate(face_lines):
f.set_data([], [])
#line.set_data([], [])
#line2.set_data([], [])
#line3.set_data([], [])
#line4.set_data([], [])
#time_text.set_text('')
#energy_text.set_text('')
#beta_text.set_text('')
return face_lines #line, line2, #line3, time_text, energy_text, beta_text
def animate_aux(i, bg_int, faces, face_lines):
"""perform animation step"""
bg_int.sample()
for k, f in enumerate(face_lines):
f.set_data(face_position(bg_int, k, faces))
## Fix for multi face animations.
#line.set_data(face_position(bg_int, 0, faces))
#line2.set_data(face_position(bg_int, 1, faces))
#time_text.set_text('time = %.1f' % tle.time_elapsed)
#energy_text.set_text('residual = %.6f' % tle.res())
#beta_text.set_text('estimate = %.4f' % tle.angle_occupation(0, ang_val, ang_tol))
return face_lines #line3, line4, time_text, energy_text, beta_text
def bg_animation(bg_int, faces, save_animation=False, L=1.0):
"""
"""
fig = plt.figure()
ax = fig.add_subplot(111,
aspect='equal',
autoscale_on=False,
xlim=(-2.0, 2.0),
ylim=(-2.0, 2.0))
ax.grid()
face_lines = ()
for f in faces:
temp_line, = ax.plot([], [], 'o-', lw=2)
face_lines += (temp_line,)
animate = lambda x: animate_aux(x, bg_int, faces, face_lines)
init = lambda: init_aux(face_lines)
# choose the interval based on dt and the time to animate one step
t0 = time()
animate(0)
t1 = time()
interval = 1000 * (L * bg_int.h) - (t1 - t0)
ani = animation.FuncAnimation(fig,
animate,
frames=300,
interval=interval,
blit=True,
init_func=init)
if save_animation == True:
# save the animation as an mp4. This requires ffmpeg or mencoder to be
# installed. The extra_args ensure that the x264 codec is used, so that
# the video can be embedded in html5. You may need to adjust this for
# your system: for more information, see
# http://matplotlib.sourceforge.net/api/animation_api.html
ani.save('triangular_linkage_diffusion.mp4', fps=3, extra_args=['-vcodec', 'libx264'])
plt.show()
poly_name = 'octahedron'
int_num = 10
boundary_name = 'none'
manifold_name = poly_name + "__" + str(int_num)
scheme = 'rej'
h = 0.01
N = 10
n, dim, x0, masses, links, lengths, faces = bga.load_bg_int(poly_name, int_num)
z = mrbm.MRBM(manifold_name, boundary_name, x0, h, scheme, run_args={'N': N})
z.sample(N=1000)
#------------------------------------------------------------
# set up figure and animation
#line, = ax.plot([], [], 'o-', lw=2)
#line2, = ax.plot([], [], 'o-', lw=2)
#line3, = ax.plot([], [], 'o-', lw=2)
#line4, = ax.plot([], [], 'o-', lw=2)
#time_text = ax.text(0.02, 0.95, '', transform=ax.transAxes)
#energy_text = ax.text(0.02, 0.90, '', transform=ax.transAxes)
#beta_text = ax.text(0.02, 0.85, '', transform=ax.transAxes)
bg_animation(z, faces)