-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathapic_example_01.py
More file actions
65 lines (53 loc) · 1.61 KB
/
Copy pathapic_example_01.py
File metadata and controls
65 lines (53 loc) · 1.61 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
from pyCubbyFlow import (
APICSolver3,
Frame,
Logging,
RigidBodyCollider3,
Sphere3,
VolumeParticleEmitter3,
)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
ANIM_NUM_FRAMES = 360
ANIM_FPS = 60
def main():
# Create APIC solver
resX = 32
solver = APICSolver3(resolution=(resX, 2 * resX, resX), domainSizeX=1.0)
# Setup emitter
sphere = Sphere3(center=(0.5, 1.0, 0.5), radius=0.15)
emitter = VolumeParticleEmitter3(implicitSurface=sphere, spacing=1.0 / (2 * resX))
solver.particleEmitter = emitter
# Setup collider
anotherSphere = Sphere3(center=(0.5, 0.5, 0.5), radius=0.15)
collider = RigidBodyCollider3(surface=anotherSphere)
solver.collider = collider
# Visualization
fig = plt.figure(figsize=(3, 6))
ax = fig.add_axes([0, 0, 1, 1], frameon=False)
ax.set_xlim(0, 1)
ax.set_xticks([])
ax.set_ylim(0, 2)
ax.set_yticks([])
# Make first frame
frame = Frame(0, 1.0 / ANIM_FPS)
solver.Update(frame)
frame.Advance()
# Visualization
pos = np.array(solver.particleSystemData.positions, copy=False)
scat = ax.scatter(pos[:, 0], pos[:, 1])
# Animation
def updateFig(*args):
solver.Update(frame)
frame.Advance()
pos = np.array(solver.particleSystemData.positions, copy=False)
scat.set_offsets(np.vstack((pos[:, 0], pos[:, 1])).transpose())
return (scat,)
animation.FuncAnimation(
fig, updateFig, frames=ANIM_NUM_FRAMES, interval=1, blit=True
)
plt.show()
if __name__ == "__main__":
Logging.Mute()
main()