Difference between revisions of "Slow the turtle down"
From JSXGraph Wiki
Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
A WASSERMANN (talk | contribs) |
||
Line 1: | Line 1: | ||
+ | This is an example, where the turtle runs controlled by the setTimeout() method | ||
+ | of JavaScript. | ||
<html> | <html> | ||
<form><input type="button" value="run" onclick="run(100)"></form> | <form><input type="button" value="run" onclick="run(100)"></form> | ||
Line 15: | Line 17: | ||
} | } | ||
</jsxgraph> | </jsxgraph> | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <html> | ||
+ | <form><input type="button" value="run" onclick="run(100)"></form> | ||
+ | </html> | ||
+ | <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) { | ||
+ | if (n>0) { | ||
+ | t.fd(20); | ||
+ | t.lt(90*(1-n/100)); | ||
+ | var st = 'run(' + (n-1) + ')'; | ||
+ | setTimeout(st,50); | ||
+ | } | ||
+ | } | ||
+ | </jsxgraph> | ||
+ | </source> | ||
+ | |||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Turtle Graphics]] | [[Category:Turtle Graphics]] |
Revision as of 16:18, 25 February 2009
This is an example, where the turtle runs controlled by the setTimeout() method of JavaScript.
<html>
<form><input type="button" value="run" onclick="run(100)"></form>
</html>
<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) {
if (n>0) {
t.fd(20);
t.lt(90*(1-n/100));
var st = 'run(' + (n-1) + ')';
setTimeout(st,50);
}
}
</jsxgraph>