Last active
September 20, 2020 02:27
-
-
Save Tremeschin/4566b6afd03644d04b80ba46d18ccaad to your computer and use it in GitHub Desktop.
18 lines Maldelbrot fractal set generator in Python
This file contains 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
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
perhaps adding custom resolution, fixing gradients on max iteration