Here it is, do you remember what happens when you drop a ball in flowing water? (Actually the fluid simulated looks something more dense than water).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
import random | |
fig = plt.figure() | |
ax1 = fig.add_subplot(1,1,1) | |
def fun(x): | |
if x!=0: | |
return 2*np.sin(4/3*x+2)/x | |
else: | |
return 1 | |
counter = 1 | |
def animate(i): | |
global x,y,counter | |
counter += 0.2 | |
ax1.clear() | |
plt.xlim(0,50) | |
plt.ylim(-2,2) | |
plt.plot([x for x in range(50)],[-0 for x in range(50)],lw=2,color="cyan") | |
plt.plot(counter,fun(counter),color="red",marker="o",ms=20) | |
ani = animation.FuncAnimation(fig,animate,interval=1) | |
plt.show() |
No comments:
Post a Comment