Slow the turtle down: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
<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',{unitX:1, unitY:1, originX:250, originY:250}); | ||
var t = brd.createElement('turtle',[100,-50],{fillColor:'#ff8800',fillOpacity:0.2}); | var t = brd.createElement('turtle',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2}); | ||
t.setPensize(5); | |||
function run(n) { | function run(n) { | ||
Line 24: | Line 25: | ||
<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',{unitX:1, unitY:1, originX:250, originY:250}); | ||
var t = brd.createElement('turtle',[100,- | var t = brd.createElement('turtle',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2}); | ||
t.setPensize(5); | |||
function run(n) { | function run(n) { |
Revision as of 14:43, 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',[100,-50],{strokeOpacity:0.7,fillColor:'#ff8800',fillOpacity:0.2});
t.setPensize(5);
function run(n) {
if (n>0) {
t.fd(20);
t.lt(90*(1-n/100));
var st = 'run(' + (n-1) + ')';
setTimeout(st,50);
}
}
</jsxgraph>