Multiple turtles: Difference between revisions

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


function run() {
function run() {
   var code = $('inputtext').value;
   var code = document.getElementById('inputtext').value;
   if (code=='') { return; }
   if (code=='') { return; }
   eval(code);
   eval(code);

Revision as of 19:45, 29 October 2009


Output

The underlying JavaScript code

var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t1 = brd.createElement('turtle');
var t2 = brd.createElement('turtle');

t1.setPos(200,0);
t2.setPos(0,0);
var n = 64;
var delta = 360.0/n;
function chase() {
    t1.fd(20);
    t1.lt(delta);
    t2.lookTo(t1.pos);
    t2.fd(20);
    action = setTimeout(chase,100);
}
chase();