Random walks: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) 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: | 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> | ||
===External links=== | ===External links=== | ||
* [ | * [] | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Turtle Graphics]] | [[Category:Turtle Graphics]] |
Revision as of 18:23, 26 May 2009
Source code
<jsxgraph width="600" height="600">
</jsxgraph>
External links
- []