aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker.js
diff options
context:
space:
mode:
Diffstat (limited to 'worker.js')
-rw-r--r--worker.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/worker.js b/worker.js
new file mode 100644
index 0000000..f89a699
--- /dev/null
+++ b/worker.js
@@ -0,0 +1,14 @@
+let canvas, screen;
+
+self.onmessage = (msg) => {
+ if (msg.data == "clear") {
+ screen.clearRect(0, 0, canvas.width, canvas.height);
+ } else if ("canvas" in msg.data) {
+ canvas = msg.data.canvas;
+ screen = canvas.getContext("2d");
+ } else {
+ [color, x, y, width, height] = msg.data;
+ screen.fillStyle = color;
+ screen.fillRect(x, y, width, height);
+ }
+};