-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.py
81 lines (50 loc) · 1.4 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
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
from datetime import datetime
import math
import time
from PIL import Image
import ray
ray.init()
ARTIFICIAL_SLOWDOWN = 0.01
FILL = " -+o%#@"
ZOOM = 100000
ASPECT_RATIO = 2.0
SIZE_X = 200
SIZE_Y = 50
X_RANGE = (-.743643135 - 1.0 / ZOOM, -.743643135 + 1.0 / ZOOM)
Y_RANGE = (.131825963 - 1.0 / (ZOOM * ASPECT_RATIO), .131825963 + 1.0 / (ZOOM * ASPECT_RATIO))
X_STEP = (X_RANGE[1] - X_RANGE[0]) / SIZE_X
Y_STEP = (Y_RANGE[1] - Y_RANGE[0]) / SIZE_Y
V_RANGE = (0.0, 1.0)
output = ""
MAX_ITER = 500
def draw_value(v):
return FILL[math.floor((v - V_RANGE[0]) / (V_RANGE[1] - V_RANGE[0]) * (len(FILL) - 1) )]
def draw_pixel(v):
return math.floor(v * 256)
@ray.remote
def mandel(x0, y0):
x = 0.0
y = 0.0
i = 0
while x * x + y * y < 4 and i < MAX_ITER:
x1 = x * x - y * y + x0
y = 2 * x * y + y0
x = x1
i += 1
# time.sleep(ARTIFICIAL_SLOWDOWN)
return draw_value(i / MAX_ITER)
start = datetime.now()
results = list()
for ys in range(0, SIZE_Y):
y = Y_RANGE[0] + Y_STEP * ys
for xs in range(0, SIZE_X):
x = X_RANGE[0] + X_STEP * xs
results.append(mandel.remote(x, y))
print("end calculations: ", datetime.now() - start)
for ys in range(0, SIZE_Y):
for xs in range(0, SIZE_X):
output += ray.get(results.pop(0))
output += "\n"
end = datetime.now()
print(output)
print("finished: ", datetime.now() - start)