Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Created September 12, 2022 19:32
Show Gist options
  • Save marmakoide/d297bb47d0213c653d58cc59cd00c74f to your computer and use it in GitHub Desktop.
Save marmakoide/d297bb47d0213c653d58cc59cd00c74f to your computer and use it in GitHub Desktop.
Demonstrates how to compute a Julia fractal efficiently in pure Python + Numpy
import numpy
from matplotlib import pyplot as plot
N = 256
C = -0.4 + 0.6j
max_epoch_count = 1024
# Initialization
T = numpy.linspace(-2., 2., N)
X = numpy.tile(T, (N, 1))
Y = X.T
Z = X + 1j * Y
Z_count = numpy.zeros((N, N))
# Iterations
for epoch in range(max_epoch_count):
mask = numpy.abs(Z ) < 2.
Z[mask] = Z[mask] ** 2 + C
Z_count[mask] += 1
# Plot
plot.imshow(Z_count, cmap = 'Spectral')
plot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment