Skip to content

Instantly share code, notes, and snippets.

@Tremeschin
Last active September 20, 2020 02:27
Show Gist options
  • Save Tremeschin/4566b6afd03644d04b80ba46d18ccaad to your computer and use it in GitHub Desktop.
Save Tremeschin/4566b6afd03644d04b80ba46d18ccaad to your computer and use it in GitHub Desktop.
18 lines Maldelbrot fractal set generator in Python
from PIL import Image
import numpy as np
res = 2000
x = np.linspace(-2, 0.5, res)
y = np.linspace(-1.1, 1.1, res)
c = np.empty((res, res), dtype=complex)
for i in range(c.shape[0]):
c[i] = x + y[i]*1j
m = c.copy()
for k in range(200):
m = np.square(m) + c
m[np.abs(m) > 10] = k
m = np.abs(m)
m = m/np.max(m)
m[np.isnan(m)][np.abs(m) > 10] = 0
m *= 255
img = Image.fromarray(m.reshape(res, res)).convert("RGB")
img.save("mandelbrot.jpg")
@Tremeschin
Copy link
Author

perhaps adding custom resolution, fixing gradients on max iteration

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