-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbounce_task.py
More file actions
65 lines (41 loc) · 1.13 KB
/
bounce_task.py
File metadata and controls
65 lines (41 loc) · 1.13 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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
dots = np.random.rand(1000,4)
dots[:,2:] -= 0.5
dots[:,2:] *= 0.01
def main():
fig, ax = plt.subplots()
ax.set_xlim(0,1)
ax.set_ylim(0,1)
xs = dots[:,0]
ys = dots[:,1]
line, = ax.plot([],[],'b.',ms=16)
def animate(i):
timestep()
line.set_data(xs,ys) # update the data
return line,
ani = animation.FuncAnimation(fig, animate,
interval=25,
blit=True)
# ani.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
# or
plt.show()
def timestep():
dots[:,:2] += dots[:,2:]
# gravity
# dots[:,3] -= 0.001
# bounce off walls
# cross_left = dots[:,0] < 0.
# ...
# collision()
main()
# Based on
#
# Animation of Elastic collisions with Gravity
#
# author: Jake Vanderplas
# email: vanderplas@astro.washington.edu
# website: http://jakevdp.github.com
# license: BSD
# Please feel free to use and modify this, but keep the above information. Thanks!