Skip to content

Commit ce38227

Browse files
committed
update some billiards features
1 parent 16cc64d commit ce38227

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/environments/billiards.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def __init__(self, T=128, n=2, r=None, m=None, eps=0.5, SIZE=10):
4040

4141
self.X = np.zeros((self.T, self.n, 2), dtype=np.float)
4242
self.v = np.random.randn(self.n, 2)
43-
self.v /= self.norm(self.v)*0.5
43+
self.vnorm = self.norm(self.v)
44+
self.v /= self.vnorm*0.5
4445

4546
self.x = self.config()
4647

src/run_billiards_example.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Billiards Example."""
22
from __future__ import print_function
33

4+
import numpy as np
5+
46
import matplotlib.pyplot as plt
57
from matplotlib.animation import FuncAnimation
68

@@ -9,18 +11,20 @@
911
resolution = 128
1012
time_steps = 25
1113

12-
env = Billiards(T=time_steps)
14+
env = Billiards(T=time_steps, SIZE=10, r=np.array([0.6]*2))
1315
env.make_frames(resolution)
1416

1517
frames = env.frames
1618
num_frames = frames.shape[0]
1719

1820
fig = plt.figure()
1921

22+
2023
def update(t):
2124
plt.imshow(frames[t], cmap="gray")
2225

23-
if __name__=="__main__":
26+
27+
if __name__ == "__main__":
2428
# FuncAnimation will call the 'update' function for each frame
2529
anim = FuncAnimation(fig, update, frames=time_steps, interval=200)
26-
anim.save('billiards.gif',writer='imagemagick');
30+
anim.save('billiards-test.gif', writer='imagemagick')

0 commit comments

Comments
 (0)