Created
October 14, 2022 10:56
-
-
Save Especuloide/6c721553aeef665a6c9c1e30404d4d07 to your computer and use it in GitHub Desktop.
Semi-Circular Waves
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.animation as animation | |
from matplotlib import pyplot | |
hr = 1000 | |
vr = 1000 | |
fig, g = pyplot.subplots(figsize=(hr/100,vr/100)) | |
pyplot.subplots_adjust(top = 0.979, left = 0.024, right = 0.972, bottom = 0.039) | |
bkg = "silver" | |
pyplot.rcParams['axes.facecolor'] = bkg | |
pyplot.rcParams['savefig.facecolor'] = bkg | |
fr = 80 # Number of frames | |
mx = 0 | |
def update(*args) : | |
pyplot.clf() | |
global fig, g, mx | |
# Equation - I found the equation here : https://www.desmos.com/calculator/e5xncapcnp | |
# am = amplitude | |
# n = Fine tunning | |
am = 40 | |
n = 1.2 | |
ex1 = np.arange(0+mx,hr+mx) # mx = "X" movement | |
Ey1 = am * np.sqrt( - (2 * np.arcsin( np.sin( (np.pi*ex1)/(2*am) + (n*np.pi) ) ) / np.pi ) ** 2 + 1) * np.sign( np.cos( (np.pi*ex1)/(2*am) + (n*np.pi) )) | |
Ey1 = Ey1 * 1.2 # More fine tunning | |
for p in range(0,len(ex1),8) : # Steps of 8 gave a good visual balance. | |
pyplot.plot(ex1[p], Ey1[p]+400, color = 'black', linewidth = None, marker = 'o', ms = 7 ) | |
pyplot.plot(ex1[p], -Ey1[p]+200, color = 'black', linewidth = None, marker = 'o', ms = 7 ) | |
pyplot.grid(False) | |
pyplot.axis("OFF") | |
pyplot.xlim(-4, 601) | |
pyplot.ylim(0,600) | |
mx -= 2 # rate of "X" sliding. | |
return () | |
def init() : | |
return() | |
o = 1 # Non 1 = single frame - usefull to adjust the plot. | |
if o == 1 : | |
anim = animation.FuncAnimation(fig, update, init_func=init, blit = True, frames=fr, repeat = False) | |
sf = 'Circular_Waves.gif' | |
Sname1 = "C://Users//Rober//Desktop//_" + sf # Mind the directory | |
anim.save(Sname1, writer="ffmpeg", fps=24) | |
else : | |
update() | |
Author
Especuloide
commented
Oct 14, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment