Multiple turtles: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 3: Line 3:
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxturtle.js"></script>
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
t1.setPos(200,0);
t1.setPos(200,0);
Line 27: Line 26:
<script language="JavaScript">
<script language="JavaScript">
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t1 = new JSXTurtleObj(brd);
var t1 = brd.createElement('turtle');
var t2 = new JSXTurtleObj(brd);
var t2 = brd.createElement('turtle');


function run() {
function run() {
Line 47: Line 46:
<source lang="javascript">
<source lang="javascript">
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t1 = new JSXTurtleObj(brd);
var t1 = brd.createElement('turtle');
var t2 = new JSXTurtleObj(brd);
var t2 = brd.createElement('turtle');


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

Revision as of 15:14, 21 January 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();