#! /bin/bash
i=1
j=1
while test $i -lt 17000000000
do echo $i $j
/usr/bin/python3 <<FIN
''' fake diffraction pattern by integer overflow'''
''' incidental tweak on 1985 with Turbo Pascal '''
print ("please wait")
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm

# make these smaller to increase the resolution
dx, dy = 1, 1

modulo=$i  # even overflows are fake

# generate 2 2d grids for the x & y bounds
y, x = np.mgrid[-200:200+dy:dy, -200:200+dx:dx]
# less fluffy # z = abs((x**2+y**2)%modulo - modulo/2)
z = ((x**2+y**2)%modulo - modulo/2)**2
# x and y are bounds, so z should be the value *inside* those bounds.
# Therefore, remove the last value from the z array.
z = z[:-1, :-1]

fig, ax = plt.subplots()

c = ax.pcolor(x, y, z, cmap='RdBu', vmin=0, vmax=z.max())

plt.savefig("toto.png")
FIN
mv toto.png f-$j.png
i=$(dc <<< "3k $i $i v v v * 2.169 / 1 + p")
i=$(expr "$i" : "\(.*\)\.")
test $i -lt $j && i=$j
j=$(($j + 1))
done

ffmpeg -framerate 10 -i f-%0000d.png -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p fake_diffraction.mp4
