Difference between revisions of "Turtle spiral"

From JSXGraph Wiki
Jump to navigationJump to search
 
(6 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;">for (var i=0;i<1000;i++){
+
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">for (var i=0;i<100;i++){
  t.forward(i*0.5);
+
  t.forward(i*3);
 
  t.left(71);
 
  t.left(71);
 
}
 
}
Line 11: Line 11:
  
 
<jsxgraph width="600" height="600">
 
<jsxgraph width="600" height="600">
var brd = JXG.JSXGraph.initBoard('jxgbox', {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 28: Line 28:
  
 
===Source code===
 
===Source code===
<source lang="html4strict">
+
<source lang="javascript">
<jsxgraph width="600" height="600">
+
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
var brd = JXG.JSXGraph.initBoard('jxgbox', {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);
Line 44: Line 43:
 
}
 
}
 
run();
 
run();
</jsxgraph>
 
 
</source>
 
</source>
  
Line 50: Line 48:
  
 
===External links===
 
===External links===
* [http://www.geogebra.org/de/wiki/index.php/Turtlegrafik Compare with GeoGebra]
+
* [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]
 
* [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 08: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