1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<html>
<head>
<title>JSXGraph example</title>
<link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
<script type="text/javascript" src="../distrib/jsxgraphcore.js"></script>
</head>
<body>
<h1>Multiple turtles</h1>
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">
<div id="box" class="jxgbox" style="width:600px; height:600px; overflow:hidden; "></div>
<div id="debug" style="display:block;"></div>
<script type="text/javascript">
/* <![CDATA[ */
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t1 = brd.createElement('turtle');
var t2 = brd.createElement('turtle',[],{strokeColor:'#0000aa'});
t1.hideTurtle();
t1.cs();
t1.setPos(200,0);
t2.hideTurtle();
t2.cs();
t2.setPos(0,0);
var n = 64;
var delta = 360.0/n;
function run() {
t1.fd(20);
t1.lt(delta);
t2.lookTo(t1.pos);
t2.fd(20);
active = setTimeout(run,100);
}
function clearturtle() {
clearTimeout(active);
t1.hideTurtle();
t2.hideTurtle();
t1.cs();
t2.cs();
t1.setPos(200,0);
t2.setPos(0,0);
}
/*
function run() {
t1.forward(20);
}
function clearturtle() {
t1.cs();
}
*/
/* ]]> */
</script>
</body>
</html>
|