Difference between revisions of "N-gones - Slow version"

From JSXGraph Wiki
Jump to: navigation, search
 
Line 12: Line 12:
  
 
<jsxgraph width="600" height="600">
 
<jsxgraph width="600" height="600">
var brd = JXG.JSXGraph.initBoard('jxgbox', {originX:300, originY:300, unitX:1, unitY:1});
+
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
 
var t = brd.createElement('turtle',[],{fillColor:'yellow'});
 
var t = brd.createElement('turtle',[],{fillColor:'yellow'});
 
var speed;
 
var speed;
Line 43: Line 43:
 
</jsxgraph>
 
</jsxgraph>
  
This example uses the [http://www.mediawiki.org/wiki/Extension:JSXGraph JSXGraph MediaWiki extension].
+
 
<source lang="xml">
+
== Sourcecode ==
<jsxgraph width="600" height="600">-->
+
 
var brd = JXG.JSXGraph.initBoard('jxgbox', {originX:300, originY:300, unitX:1, unitY:1});
+
<source lang="javascript">
 +
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
 
var t = brd.createElement('turtle',[],{fillColor:'yellow'});
 
var t = brd.createElement('turtle',[],{fillColor:'yellow'});
 
var speed;
 
var speed;
Line 77: Line 78:
 
   t.cs();
 
   t.cs();
 
}
 
}
</jsxgraph>
 
 
</source>
 
</source>
  
 
[[Category:Examples]]
 
[[Category:Examples]]
 
[[Category:Turtle Graphics]]
 
[[Category:Turtle Graphics]]

Latest revision as of 11:56, 8 June 2011



Sourcecode

var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
var t = brd.createElement('turtle',[],{fillColor:'yellow'});
var speed;

function innerloop(i,j,ne,sz) {
   if (i>0) {
     if (j==ne) { t.rt(360/ne); }
     t.rt(360/ne);
     t.fd(sz);
     j--;
     if (j<=0) {
       j=ne;
       i--;
     }
     var st = 'innerloop('+(i)+','+(j)+','+(ne)+','+(sz)+')';
     setTimeout(st,speed);
   }
}

function ngon(ne,sz) {
  innerloop(ne,ne,ne,sz);
}

function runturtle() {
  var code = document.getElementById('inputtext').value;
  if (code=='') { return; }
  eval(code);
}
function clearturtle() {
  t.cs();
}