Last active
April 28, 2021 01:44
-
-
Save omegahm/e823a68c201406d32a94 to your computer and use it in GitHub Desktop.
Quasicrystals in Python
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import bohrium as np | |
from math import pi | |
import matplotlib.pyplot as plt | |
import matplotlib.colors as colors | |
fig = plt.figure() | |
plt.xticks([]) | |
plt.yticks([]) | |
k = 5 # number of plane waves | |
stripes = 37 # number of stripes per wave | |
N = 512 # image size in pixels | |
ite = 30 # iterations | |
phases = np.arange(0, 2*pi, 2*pi/ite) | |
image = np.empty((N, N)) | |
d = np.arange(-N/2, N/2, dtype=np.float64) | |
xv, yv = np.meshgrid(d, d) | |
theta = np.arctan2(yv, xv) | |
r = np.log(np.sqrt(xv*xv + yv*yv)) | |
r[np.isinf(r) == True] = 0 | |
tcos = theta * np.cos(np.arange(0, pi, pi/k))[:, np.newaxis, np.newaxis] | |
rsin = r * np.sin(np.arange(0, pi, pi/k))[:, np.newaxis, np.newaxis] | |
inner = (tcos - rsin) * stripes | |
cinner = np.cos(inner) | |
sinner = np.sin(inner) | |
i = 0 | |
for phase in phases: | |
image[:] = np.sum(cinner * np.cos(phase) - sinner * np.sin(phase), axis=0) + k | |
plt.imshow(image.copy2numpy(), cmap="RdGy") | |
fig.savefig("quasi-{:03d}.png".format(i), bbox_inches='tight', pad_inches=0) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's actually quite practical. The duration basically sets the speed of your gif (since it is looping) so it makes sense. As long as you are testing the animation, you make the rendering very quick by setting the fps to 5, and when you are happy with the result you set the fps to 30 and get a final, much fluider gif.
If you want to control the number of frames, is see these solutions:
n_frames / duration
You may also be interested by these other examples.