Programming turtle graphics

From JSXGraph Wiki
Jump to: navigation, search

Input


Output

Log window



Source code

<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br />
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear log" onClick="clearlog()">
</form>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var t = brd.create('turtle');

function run() {
  brd.suspendUpdate();
  var code = document.getElementById('inputtext').value;
  if (code=='') { return; }
  eval(code);
  document.getElementById('logwindow').innerHTML += code+'\n';
  brd.unsuspendUpdate();
}

function clearturtle() {
  t.cs();
  //document.getElementById('inputtext').value = 't.fd(100);';
}
function clearlog() {
  document.getElementById('logwindow').innerHTML = '';
}