-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmandelbrot_spirals.py
85 lines (71 loc) · 1.84 KB
/
mandelbrot_spirals.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
"""Vykreslení spirál v Mandelbrotově množině."""
import palette_mandmap
from PIL import Image
IMAGE_WIDTH = 512
IMAGE_HEIGHT = 384
def mandelbrot(cx, cy, maxiter):
"""Výpočet, kolik iterací je nutné pro opuštění jednotkového kruhu."""
c = complex(cx, cy)
z = 0
for i in range(maxiter):
if abs(z) > 2:
return i
z = z * z + c
return 0
def recalc_fractal(image, palette, xmin, ymin, xmax, ymax, maxiter=1000):
"""Přepočet celého fraktálu."""
width, height = image.size # rozměry obrázku
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
image = Image.new("RGB", (IMAGE_WIDTH, IMAGE_HEIGHT))
recalc_fractal(
image,
palette_mandmap.palette,
-0.769824999999999998320,
-0.109270000000000000000,
-0.766247499999999998426,
-0.106570000000000000000,
1000,
)
image.save("spiral_1.png")
recalc_fractal(
image,
palette_mandmap.palette,
-0.171119200000000013445,
0.657309400000000000000,
-0.169318975000000013445,
0.658660750000000000000,
1000,
)
image.save("spiral_2.png")
recalc_fractal(
image,
palette_mandmap.palette,
-0.207190825000000012496,
0.676656624999999999983,
-0.206107925000000012496,
0.677468799999999999983,
1000,
)
image.save("spiral_3.png")
recalc_fractal(
image,
palette_mandmap.palette,
-0.540623850000000003876,
0.523798050000000000019,
-0.532306600000000003876,
0.530031950000000000019,
1000,
)
image.save("spiral_4.png")