-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmandelbrot_z^3.py
52 lines (38 loc) · 1.29 KB
/
mandelbrot_z^3.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""Renderer of Mandelbrot fractal variant z^3."""
from PIL import Image
# textura by mela byt ctvercova a jeji sirka i vyska by mela byt
# mocninou cisla 2
IMAGE_WIDTH = 512
IMAGE_HEIGHT = 512
def mandelbrot(cx, cy, maxiter):
"""Calculate number of iterations for given complex number to escape from set."""
c = complex(cx, cy)
z = 0
for i in range(maxiter):
if abs(z) > 2:
return i
z = z**3 + c
return 0
def recalc_fractal(image, palette, xmin, ymin, xmax, ymax, maxiter=1000):
"""Recalculate the whole fractal and render the set into given image."""
width, height = image.size # rozmery obrazku
stepx = (xmax - xmin) / width
stepy = (ymax - ymin) / height
y1 = ymin
for y in range(height):
x1 = xmin
for x in range(width):
i = mandelbrot(x1, y1, maxiter)
i = 3 * i % 256
color = (palette[i][0], palette[i][1], palette[i][2])
image.putpixel((x, y), color)
x1 += stepx
y1 += stepy
def main():
import palette_mandmap
image = Image.new("RGB", (IMAGE_WIDTH, IMAGE_HEIGHT))
recalc_fractal(image, palette_mandmap.palette, -1.5, -1.5, 1.5, 1.5, 1000)
image.save("mandelbrot_z^3.png")
if __name__ == "__main__":
main()