Random walks: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 25: Line 25:


<jsxgraph width="600" height="600">
<jsxgraph width="600" height="600">
var brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 300, originY: 300, unitX: 2, unitY: 2});
var brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 300, originY: 300, unitX: 3, unitY: 3});
var t = brd.createElement('turtle');
var t = brd.createElement('turtle');


function run() {
function run() {
   var i,j;
   var i,j,dist,sumdist=0.0;
   var stepSize = 5;  
   var stepSize = 5;  
   brd.suspendUpdate();
   brd.suspendUpdate();
Line 39: Line 39:
         t.forward(stepSize);
         t.forward(stepSize);
     }
     }
    dist = t.pos[0]*t.pos[0]+t.pos[1]*t.pos[1];
    sumdist += dist;
     t.home();
     t.home();
   }
   }
 
  alert(sumdist);
   brd.unsuspendUpdate();
   brd.unsuspendUpdate();
}
}
Line 54: Line 56:
</jsxgraph>
</jsxgraph>
</source>
</source>
* Hints how to "[[Slow the turtle down]]"


===External links===
===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]]

Revision as of 18:23, 26 May 2009

Number of random walks:

Source code

<jsxgraph width="600" height="600">
</jsxgraph>

External links

  • []