aframe-lsystem-component
Version:
L-System/LSystem component for A-Frame to draw 3D turtle graphics. Using Lindenmayer as backend.
28 lines (21 loc) • 701 B
JavaScript
// Require instead of importScripts because we use webpack
// with worker-loader for compiling source: https://github.com/webpack/worker-loader
import LSystem from 'lindenmayer';
let lsystem = new LSystem({});
let timeout = {};
onmessage = function(e) {
// wait a few ms to start thread, to be able to cancel old tasks
clearTimeout(timeout);
timeout = setTimeout(function() {
lsystem.setAxiom(e.data.axiom);
lsystem.clearProductions();
for (let p of e.data.productions) {
lsystem.setProduction(p[0], p[1]);
}
lsystem.iterate(e.data.iterations);
postMessage({
result: lsystem.getString(),
initial: e.data
});
}, 20);
};