Guest User

lsystem.js

a guest
Oct 11th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // wait for page to load completely
  2. window.onload = function() {
  3.   var ls = require('./lsystem.js');
  4.  
  5.   var wonk = ls.soundoff("wonk!");
  6.  
  7.   // Set up the algae demo
  8.   var aIter = document.getElementById("algae-iterations"),
  9.       aOut = document.getElementById("algae-output");
  10.   aOut.value = ls.algae(0);
  11.   aIter.onchange = function() {
  12.     aOut.value = ls.algae(aIter.value);
  13.   }
  14.  
  15.   // Set up the Pathagoras Tree demo
  16.   var bIter = document.getElementById("tree-iterations"),
  17.       bOut = document.getElementById("tree-output"),
  18.       bCanvas = document.getElementById("tree-canvas"),
  19.       bCtx = bCanvas.getContext("2d");
  20.   bOut.value = ls.pythagorasTree(0);
  21.   ls.render(380, 480, bCtx);
  22.   bIter.onchange = function() {
  23.     bOut.value = ls.pythagorasTree(bIter.value).replace(/\([0-9]+\)/g, "");
  24.     bCtx.clearRect(0,0, bCanvas.width, bCanvas.height);
  25.     ls.render(380, 480, bCtx);
  26.   }
  27.  
  28.   // Set up the Koch Curve demo
  29.   var cIter = document.getElementById("koch-iterations"),
  30.       cOut = document.getElementById("koch-output"),
  31.       cCanvas = document.getElementById("koch-canvas"),
  32.       cCtx = cCanvas.getContext("2d");
  33.   cOut.value = ls.kochCurve(0);
  34.   ls.render(30, 450, cCtx);
  35.   cIter.onchange = function() {
  36.     cOut.value = ls.kochCurve(cIter.value);
  37.     cCtx.clearRect(0, 0, cCanvas.width, cCanvas.height);
  38.     ls.render(30, 450, cCtx);
  39.   }
  40.  
  41. };
Advertisement
Add Comment
Please, Sign In to add comment