Difference between revisions of "Turtle spiral"

From JSXGraph Wiki
Jump to navigationJump to search
Line 1: Line 1:
 
<html>
 
<html>
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">  
+
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">for (var i=0;i<200;i++){
for (var i=0;i<200;i++){
 
 
  t.forward(i*0.5);
 
  t.forward(i*0.5);
 
  t.left(30);
 
  t.left(30);
Line 30: Line 29:
 
===Source code===
 
===Source code===
 
<source lang="html4strict">
 
<source lang="html4strict">
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
+
<jsxgraph width="600" height="600">
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
+
var brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 300, originY: 300, unitX: 1, unitY: 1});
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
+
var t = brd.createElement('turtle');
<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()">
+
function run() {
<input type="button" value="clear" onClick="clearturtle()">
+
  brd.suspendUpdate();
<input type="button" value="clear log" onClick="clearlog()">
+
  var code = $('inputtext').value;
</form>
+
  if (code=='') { return; }
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
+
  eval(code);
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
+
  brd.unsuspendUpdate();
</source>
+
}
<source lang="javascript">
+
function clearturtle() {
 +
  t.cs();
 +
}
 +
</jsxgraph>
 
</source>
 
</source>
  

Revision as of 17:38, 25 March 2009


Source code

<jsxgraph width="600" height="600">
var brd = JXG.JSXGraph.initBoard('jxgbox', {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);
  brd.unsuspendUpdate();
}
function clearturtle() {
  t.cs();
}
</jsxgraph>