Multiple turtles: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<html>
<html>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<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/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 22: Line 18:
</form>
</form>
</html>
</html>
===Output===
===Output===
<html>
<jsxgraph box="box" width="600" height="600">
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
<script language="JavaScript">
var t1 = brd.create('turtle');
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t2 = brd.create('turtle');
var t1 = new JSXTurtleObj(brd);
var t2 = new JSXTurtleObj(brd);


function run() {
function run() {
   var code = $('inputtext').value;
   var code = document.getElementById('inputtext').value;
   if (code=='') { return; }
   if (code=='') { return; }
   eval(code);
   eval(code);
Line 40: Line 35:
   t2.cs();
   t2.cs();
}
}
</script>
</jsxgraph>
</html>
 
===The underlying JavaScript code===
 
<source lang="javascript">
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]});
var t1 = brd.create('turtle');
var t2 = brd.create('turtle');


===References===
t1.setPos(200,0);
This example is from
t2.setPos(0,0);
* [http://de.wikipedia.org/wiki/Logo_(Programmiersprache) http://de.wikipedia.org/wiki/Logo_(Programmiersprache)]
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();
</source>


[[Category:Examples]]
[[Category:Examples]]
[[Category:Turtle Graphics]]
[[Category:Turtle Graphics]]

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();