-
-
Save asnramos/06832137bb7db4112bf68a05d7d11acd to your computer and use it in GitHub Desktop.
Interference pattern animation
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 pyplot | |
import matplotlib.animation as animation | |
pyplot.style.use("dark_background") | |
fig, g = pyplot.subplots(figsize=(6,6)) | |
pyplot.subplots_adjust(top = 1.0, left = 0.00, right = 1.0, bottom = 0.00) | |
def circ (r, pa) : # Drawing function | |
# r = Circle size, pa = slide counter | |
# Coordinates lists | |
Ex = [] | |
Ey = [] | |
### Circle points equation | |
p = 100 | |
for x in range(0,p) : # | |
Ex.append(np.cos(4.0*np.pi/p*x)*r ) | |
Ey.append(np.sin(4.0*np.pi/p*x)*r ) | |
### | |
### Line plotting | |
for mk in range(0, int(len(Ex)/2)) : | |
for l in range(5+pa, 15+pa) : | |
pyplot.plot( [Ex[mk], Ex[l]/3], [Ey[mk], Ey[l]/3], c = "white", linewidth = 0.3 ) | |
return | |
fr = 50 # Number of frames | |
lim = 0 # Counter | |
def update(*args) : # Animation function | |
global lim | |
pyplot.clf() | |
circ(8, lim) | |
pyplot.grid(False) | |
pyplot.ylim(-10,10) | |
pyplot.xlim(-10,10) | |
lim +=1 | |
return() | |
def init() : # Also part of animation function | |
return() | |
anim = animation.FuncAnimation(fig, update, init_func=init, blit = True, frames=fr, repeat = False) | |
sf = "Interference.gif" | |
Sname = "C:\\Users\\rober\\Desktop\\_" + sf | |
anim.save(Sname, writer="imagemagick", fps=14) # fps = frames per second | |
# You must have imagemagick installed in you computer : | |
# https://www.imagemagick.org/script/index.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment