Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Interference pattern animation
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
@Especuloide
Copy link
Author

Especuloide commented Jul 18, 2020

_Interference

Loading

@asnramos
Copy link

asnramos commented Jul 23, 2020

Genial...!!!! Para enseñar de manera interesante y motivadora a los chicos..!!! Gracias por compartir..!!!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment