-
Notifications
You must be signed in to change notification settings - Fork 2
/
mandelbrot.py
35 lines (30 loc) · 1.07 KB
/
mandelbrot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import time
def mandelbrot(c, max_iter):
z = 0
for n in range(max_iter):
if abs(z) > 2:
return n / max_iter
z = z * z + c
return 1
def generate_mandelbrot(center_x, center_y, zoom, size=70, max_iter=256):
zoom = 1.05 ** (zoom - 1)
pixels = np.zeros((size, size))
for x in range(size):
for y in range(size):
re = (x - size / 2) / (0.5 * zoom * size) + center_x
im = (y - size / 2) / (0.5 * zoom * size) + center_y
c = complex(re, im)
pixels[y, x] = mandelbrot(c, max_iter)
return pixels
def run(n):
# Use this to record an entire sequence. Run a screen recorder while this runs and then
# export the frames of that move at 0.1fps, giving you one iteration per frame. You can then
# combine these frames into a video using ffmpeg. Maybe there's a better way to do this!
for i in range(n):
start = time.time()
S1 = i + 1
_ = A3
to_sleep = 10 - time.time() + start
print(to_sleep)
time.sleep(to_sleep)