Multiple turtles: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
Line 22: Line 22:
<jsxgraph box="box" width="600" height="600">
<jsxgraph box="box" width="600" height="600">
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var t1 = brd.createElement('turtle');
var t1 = brd.create('turtle');
var t2 = brd.createElement('turtle');
var t2 = brd.create('turtle');


function run() {
function run() {
Line 41: Line 41:
<source lang="javascript">
<source lang="javascript">
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var t1 = brd.createElement('turtle');
var t1 = brd.create('turtle');
var t2 = brd.createElement('turtle');
var t2 = brd.create('turtle');


t1.setPos(200,0);
t1.setPos(200,0);

Latest revision as of 13:26, 3 March 2021


Output

The underlying JavaScript code

var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var t1 = brd.create('turtle');
var t2 = brd.create('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();