Turtle spiral: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<html>
<html>
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">  
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">for (var i=0;i<100;i++){
for (var i=0;i<100;i++){
  t.forward(i*3);
  t.forward(i*0.5);
  t.left(71);
  t.left(30);
}
}
</textarea><br />
</textarea><br />
<input type="button" value="run" onClick="run()">
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear log" onClick="clearlog()">
</form>
</form>
</html>
</html>


<jsxgraph width="600" height="600">
<jsxgraph width="600" height="600">
var brd = JXG.JSXGraph.initBoard('jsxgbox', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var brd = JXG.JSXGraph.initBoard('jxgbox', {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);
Line 26: Line 24:
   t.cs();
   t.cs();
}
}
run();
</jsxgraph>
</jsxgraph>


===Source code===
===Source code===
<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 />
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear log" onClick="clearlog()">
</form>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
</source>
<source lang="javascript">
<source lang="javascript">
var brd = JXG.JSXGraph.initBoard('jxgbox', {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);
  brd.unsuspendUpdate();
}
function clearturtle() {
  t.cs();
}
run();
</source>
</source>


* Hints how to "[[Slow the turtle down]]"
* Hints how to "[[Slow the turtle down]]"
===External links===
* [http://www.geogebra.org/de/wiki/index.php/Turtlegrafik A similar construction with GeoGebra]
* [http://wiki.zum.de/Turtle-Grafik ZUM-Wiki's Turtle graphics page]


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

Latest revision as of 07:41, 9 June 2011


Source code

var brd = JXG.JSXGraph.initBoard('jxgbox', {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);
  brd.unsuspendUpdate();
}
function clearturtle() {
  t.cs();
}
run();

External links