Files
INF6B/simulations/mandelbrotset/generate.py
rattatwinko d0eaabdd87 some new stuff.
idk its all pretty fun! some C++ too!
2025-10-15 11:16:51 +02:00

20 lines
607 B
Python

from numba import njit
import numpy as np
@njit
def generate_mandelbrot(xmin, xmax, ymin, ymax, width, height, max_iter):
img = np.zeros((height, width), dtype=np.uint32)
for i in range(height):
for j in range(width):
x0 = xmin + (xmax - xmin) * j / width
y0 = ymin + (ymax - ymin) * i / height
x, y = 0.0, 0.0
iter = 0
while x*x + y*y <= 4.0 and iter < max_iter:
xtemp = x*x - y*y + x0
y = 2*x*y + y0
x = xtemp
iter += 1
img[i, j] = iter
return img