Programming turtle graphics: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
<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> | ||
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br /> | <form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br /> | ||
<input type="button" value="run" onClick="run()"> | <input type="button" value="run" onClick="run()"> | ||
Line 18: | Line 17: | ||
<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 = | var t = brd.createElement('turtle'); | ||
function run() { | function run() { | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
Line 47: | Line 46: | ||
<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> | ||
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br /> | <form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br /> | ||
<input type="button" value="run" onClick="run()"> | <input type="button" value="run" onClick="run()"> | ||
Line 58: | Line 56: | ||
<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 t = | var t = brd.createElement('turtle'); | ||
function run() { | function run() { | ||
brd.suspendUpdate(); | brd.suspendUpdate(); |
Revision as of 15:16, 21 January 2009
Input
Output
Log window
Source code
<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>
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">t.fd(100);</textarea><br />
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear log" onClick="clearlog()">
</form>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
var t = brd.createElement('turtle');
function run() {
brd.suspendUpdate();
var code = $('inputtext').value;
if (code=='') { return; }
eval(code);
$('logwindow').innerHTML += code+'\n';
//$('inputtext').value = '';
brd.unsuspendUpdate();
}
function clearturtle() {
t.cs();
//$('inputtext').value = 't.fd(100);';
}
function clearlog() {
$('logwindow').innerHTML = '';
}
</script>