toolness / tiny-turtle

Minimalist canvas-based turtle graphics in 50 lines of JS.
http://toolness.github.io/tiny-turtle/
14 stars 8 forks source link

In tutorial, do stamp() out-of-band #3

Open toolness opened 11 years ago

toolness commented 11 years ago

The stamp() function is confusing to learners; we might just want to do it ourselves at the end of the render process.

jieter commented 6 years ago

This is what I did to add the call to stamp() to every render:

diff --git a/lab/lab.js b/lab/lab.js
index b277c99..638e71a 100644
--- a/lab/lab.js
+++ b/lab/lab.js
@@ -86,10 +86,12 @@ var Lab = typeof(window) == 'undefined'
       turtle = new TinyTurtle(canvas);
       worker = new Worker(workerURL);
       worker.onmessage = function(e) {
-        if (e.data.msg == 'done')
+        if (e.data.msg == 'done') {
+          cmds.push({args: [], method: 'stamp', msg: 'turtle-methodcall'});
           finishWorker(cmds, null);
-        else
+        } else {
           cmds.push(e.data);
+        }
       };
       worker.onerror = finishWorker.bind(null, cmds);
       worker.postMessage({