Slow the turtle down: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This is an example, where the turtle runs controlled by the setTimeout() method
This is an example, where the turtle speed is controlled by the setTimeout() method
of JavaScript.
of JavaScript.
<html>
<html>
<form><input type="button" value="run" onclick="run(100)"></form>
<form><input type="button" value="run" onclick="run(100)"></form>
</html>
</html>
<jsxgraph width="500" height="500">
<jsxgraph width="500" height="500">
var brd = JXG.JSXGraph.initBoard('jxgbox',{unitX:1, unitY:1, originX:250, originY:250});
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-250, 250, 250, -250]});
var t = brd.createElement('turtle');
var t = brd.create('turtle',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2});
t.setPenSize(3);


function run(n) {
function run(n) {
Line 13: Line 15:
     t.lt(90*(1-n/100));
     t.lt(90*(1-n/100));
     var st = 'run(' + (n-1) + ')';
     var st = 'run(' + (n-1) + ')';
     setTimeout(st,50);
     setTimeout(st,25);
   }
   }
}
}
</jsxgraph>
</jsxgraph>


<source lang="xml">
<source lang="javascript">
<html>
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-250, 250, 250, -250]});
<form><input type="button" value="run" onclick="run(100)"></form>
var t = brd.create('turtle',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2});
</html>
t.setPenSize(3);
<jsxgraph width="500" height="500">
var brd = JXG.JSXGraph.initBoard('jxgbox',{unitX:1, unitY:1, originX:250, originY:250});
var t = brd.createElement('turtle');


function run(n) {
function run(n) {
Line 31: Line 30:
     t.lt(90*(1-n/100));
     t.lt(90*(1-n/100));
     var st = 'run(' + (n-1) + ')';
     var st = 'run(' + (n-1) + ')';
     setTimeout(st,50);
     setTimeout(st,25);
   }
   }
}
}
</jsxgraph>
</source>
</source>


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

Latest revision as of 13:44, 8 June 2011

This is an example, where the turtle speed is controlled by the setTimeout() method of JavaScript.

var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-250, 250, 250, -250]});
var t = brd.create('turtle',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2});
t.setPenSize(3);

function run(n) {
   if (n>0) {
     t.fd(20);
     t.lt(90*(1-n/100));
     var st = 'run(' + (n-1) + ')';
     setTimeout(st,25);
   }
}