Programming turtle graphics: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
===Input===
==Input==
* [[List of available commands]]
* [[List of available commands]]


<html>
<html>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br />
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br />
<input type="button" value="run" onClick="run()">
<input type="button" value="run" onClick="run()">
Line 12: Line 9:
</form>
</form>
</html>
</html>
===Output===
 
<html>
==Output==
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
<jsxgraph box="box" width="600" height="600">
<script language="JavaScript">
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t = brd.create('turtle');
var t = brd.createElement('turtle');
function run() {
function run() {
   brd.suspendUpdate();
   brd.suspendUpdate();
   var code = $('inputtext').value;
   var code = document.getElementById('inputtext').value;
   if (code=='') { return; }
   if (code=='') { return; }
   eval(code);
   eval(code);
   $('logwindow').innerHTML += code+'\n';
   document.getElementById('logwindow').innerHTML += code+'\n';
   //$('inputtext').value = '';
   //document.getElementById('inputtext').value = '';
   brd.unsuspendUpdate();
   brd.unsuspendUpdate();
}
}
function clearturtle() {
function clearturtle() {
   t.cs();
   t.cs();
   //$('inputtext').value = 't.fd(100);';
   //document.getElementById('inputtext').value = 't.fd(100);';
}
}
function clearlog() {
function clearlog() {
   $('logwindow').innerHTML = '';
   document.getElementById('logwindow').innerHTML = '';
}
}
</script>
</jsxgraph>
</html>
 
===Log window===
==Log window==
<html>
<html>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
</html>
</html>


===Source code===
==Source code==
<source lang="html4strict">
<source lang="html4strict">
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br />
<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="run" onClick="run()">
Line 51: Line 44:
<input type="button" value="clear log" onClick="clearlog()">
<input type="button" value="clear log" onClick="clearlog()">
</form>
</form>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
</source>
</source>
<source lang="javascript">
<source lang="javascript">
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var t = brd.createElement('turtle');
var t = brd.create('turtle');
 
function run() {
function run() {
   brd.suspendUpdate();
   brd.suspendUpdate();
   var code = $('inputtext').value;
   var code = document.getElementById('inputtext').value;
   if (code=='') { return; }
   if (code=='') { return; }
   eval(code);
   eval(code);
   $('logwindow').innerHTML += code+'\n';
   document.getElementById('logwindow').innerHTML += code+'\n';
  //$('inputtext').value = '';
   brd.unsuspendUpdate();
   brd.unsuspendUpdate();
}
}
function clearturtle() {
function clearturtle() {
   t.cs();
   t.cs();
   //$('inputtext').value = 't.fd(100);';
   //document.getElementById('inputtext').value = 't.fd(100);';
}
}
function clearlog() {
function clearlog() {
   $('logwindow').innerHTML = '';
   document.getElementById('logwindow').innerHTML = '';
}
}
</script>
</source>
</source>


* [[Slow the turtle down]]
* How to "[[Slow the turtle down]]"


[[Category:Examples]]
[[Category:Examples]]
[[Category:Turtle Graphics]]
[[Category:Turtle Graphics]]

Latest revision as of 12:00, 8 June 2011

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 = '';
}