-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
29 lines (25 loc) · 807 Bytes
/
Copy pathworker.js
File metadata and controls
29 lines (25 loc) · 807 Bytes
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
import init, { initThreadPool, mandelbrot, mandelbrot_simple, mandelbrot_parallel } from "./pkg/mandelbrot.js";
// init already called in index.js, but Safari still requires it here
try {
await init();
await initThreadPool(navigator.hardwareConcurrency);
} catch (e) {
alert("Worker: " + e)
}
onmessage = (message) => {
let [width, height, scale, iterations, centerX, centerY, renderStrategy] = message.data;
switch (renderStrategy) {
case "w":
postMessage(mandelbrot(width, height, scale, iterations, centerX, centerY))
break;
case "ws":
postMessage(mandelbrot_simple(width, height, scale, iterations, centerX, centerY))
break;
default:
postMessage(mandelbrot_parallel(width, height, scale, iterations, centerX, centerY))
break;
}
}
onerror = (e) => {
console.error(e)
}