Skip to content

Instantly share code, notes, and snippets.

@maxhumber
Created July 14, 2020 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxhumber/06b6c16af5754da37fd24482f066dfb9 to your computer and use it in GitHub Desktop.
Save maxhumber/06b6c16af5754da37fd24482f066dfb9 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import gif
def julia_quadratic(zx, zy, cx, cy, threshold):
z = complex(zx, zy)
c = complex(cx, cy)
for i in range(threshold):
z = z**2 + c
if abs(z) > 4.:
return i
return threshold - 1
x_start, y_start = -2, -2
width, height = 4, 4
density_per_unit = 200
re = np.linspace(x_start, x_start + width, width * density_per_unit )
im = np.linspace(y_start, y_start + height, height * density_per_unit)
threshold = 20
n_frames = 100
r = 0.7885
a = np.linspace(0, 2*np.pi, n_frames)
@gif.frame
def plot(i):
X = np.empty((len(re), len(im)))
cx, cy = r * np.cos(a[i]), r * np.sin(a[i])
for i in range(len(re)):
for j in range(len(im)):
X[i, j] = julia_quadratic(re[i], im[j], cx, cy, threshold)
plt.figure(figsize=(10, 10))
plt.imshow(X.T, interpolation="bicubic", cmap='magma')
plt.xticks([])
plt.yticks([])
frames = []
for i in range(n_frames):
frame = plot(i)
frames.append(frame)
gif.save(frames, 'julia_set.gif', duration=50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment