-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_worker.py
More file actions
91 lines (71 loc) · 2.32 KB
/
Copy pathsample_worker.py
File metadata and controls
91 lines (71 loc) · 2.32 KB
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
86
87
88
89
90
91
from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('skip')
this = console = postMessage = addEventListener = 0 # Prevent complaints by optional static checker
__pragma__ ('noskip')
grid = [[ [1,0,0,0,0,0,0,0], # 0
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0]],
[ [0,0,0,0,1,0,0,0], # 1
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[1,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0]],
[ [0,0,1,0,0,0,1,0], # 2
[0,0,0,0,0,0,0,0],
[1,0,1,0,1,0,1,0],
[0,0,0,0,0,0,0,0],
[0,0,1,0,0,0,1,0],
[0,0,0,0,0,0,0,0],
[1,0,1,0,1,0,1,0],
[0,0,0,0,0,0,0,0]],
[ [0,1,0,1,0,1,0,1], # 3
[1,1,1,1,1,1,1,1],
[0,1,0,1,0,1,0,1],
[1,1,1,1,1,1,1,1],
[0,1,0,0,0,1,0,1],
[1,1,1,1,1,1,1,1],
[0,1,0,1,0,1,0,1],
[1,1,1,1,1,1,1,1]]]
def mandel(width, height, max_iter, left, top, right, bottom):
fx = (right - left) / width;
fy = (top - bottom) / height;
for g in range(4):
for y in range(0, height, (1 << (3 - g))):
buffer = []
for x in range(width):
if (not (grid[g][y % 8][x % 8] == 1)):
continue
cr = left + x * fx
ci = top - y * fy
zr = cr
zi = ci
color = 0
for i in range(1, max_iter):
tmp = zr
zr = zr*zr - zi*zi + cr
zi = 2 * tmp * zi + ci
if (zr * zr + zi * zi > 4):
color = i
break
buffer.append({ 'x':x, 'y':y, 'c':color, 'size': (1 << (3 - g)) })
postMessage(buffer)
def on_message(e):
data = e.data
if (data.cmd == "start"):
console.log("Worker started!")
console.log("width={}".format(data.width))
console.log("height={}".format(data.height))
console.log("max_iter={}".format(data.max_iter))
mandel(data.width, data.height, data.max_iter, data.left, data.top, data.right, data.bottom)
console.log("Worker finished!")
else:
console.log("Unknown command!")
addEventListener("message", on_message)