Difference between revisions of "Slow the turtle down"

From JSXGraph Wiki
Jump to: navigation, search
 
Line 21: Line 21:
  
 
<source lang="javascript">
 
<source lang="javascript">
<jsxgraph width="500" height="500">
 
 
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-250, 250, 250, -250]});
 
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});
 
var t = brd.create('turtle',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2});

Latest revision as of 15: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);
   }
}