Programming turtle graphics: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) (New page: ===List of available commands=== There is a predefined turtle object ''t''. Therefore, all commands start with ''t'', like ''t.fd(100)''; * t.forward(len); or t.fd(len); * t.back(len); or ...) |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 23: | Line 23: | ||
<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> | <script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxturtle.js"></script> | ||
<form><textarea id="input" rows=3 cols=35 wrap="off" style="width:600px; float:left;"> | |||
</textarea> | |||
<input type="button" value="run" onClick="run()"> | |||
</form> | |||
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div> | <div id="box" class="jxgbox" style="width:600px; height:600px;"></div> | ||
<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 t = new JSXTurtleObj(brd); | var t = new JSXTurtleObj(brd); | ||
function run( | function run() { | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
eval($('input' | eval($('input').value); | ||
brd.unsuspendUpdate(); | brd.unsuspendUpdate(); | ||
} | } | ||
</script> | </script> | ||
</html> | </html> |
Revision as of 10:23, 21 December 2008
List of available commands
There is a predefined turtle object t. Therefore, all commands start with t, like t.fd(100);
- t.forward(len); or t.fd(len);
- t.back(len); or t.bk(len);
- t.right(angle); or t.rt(angle); ([math]\displaystyle{ 0\leq angle \leq 360 }[/math])
- t.left(angle); or t.lt(angle);
- t.penUp(); or t.pu();
- t.penDown(); or t.pd();
- t.clearScreen(); or t.cs();
- t.clean();
- t.setPos(x,y);
- t.home();
- t.hideTurtle(); or t.ht();
- t.showTurtle(); or t.st();
- t.setPenSize(size); (size: number)
- t.setPenColor(col); (col: colorString, e.g. 'red' or '#ff0000')
Interaction