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

From JSXGraph Wiki
Jump to navigationJump to search
 
(38 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<html>
 
<html>
<form><textarea id="inputtext" rows=12 cols=35 wrap="off" style="width:600px;">
+
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
function n_eck(ne,sz) {
+
<form><textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">
   for(var i=0;i<ne;i++) {
+
speed=25;
 +
t.cs().hideTurtle().setProperty({strokeWidth:4,strokeOpacity:0.6,fillOpacity:0.3});
 +
ngon(10,60);
 +
</textarea><br />
 +
<input type="button" value="run" onClick="runturtle()">
 +
<input type="button" value="clear" onClick="clearturtle()">
 +
</form>
 +
</html>
 +
 
 +
<jsxgraph width="600" height="600">
 +
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
 +
var t = brd.create('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.rt(360/ne);
 
     t.fd(sz);
 
     t.fd(sz);
 +
    j--;
 +
    if (j<=0) {
 +
      j=ne;
 +
      i--;
 +
    }
 +
    var st = 'innerloop('+(i)+','+(j)+','+(ne)+','+(sz)+')';
 +
    setTimeout(st,speed);
 
   }
 
   }
 
}
 
}
  
function mn_eck(ne,sz) {
+
function ngon(ne,sz) {
  for(var i=0;i<ne;i++) {
+
  innerloop(ne,ne,ne,sz);
 +
}
 +
function runturtle() {
 +
  var code = document.getElementById('inputtext').value;
 +
  if (code=='') { return; }
 +
  eval(code);
 +
}
 +
function clearturtle() {
 +
  t.cs();
 +
}
 +
</jsxgraph>
 +
 
 +
 
 +
== Sourcecode ==
 +
 
 +
<source lang="javascript">
 +
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
 +
var t = brd.create('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.rt(360/ne);
     n_eck(ne,sz);
+
     t.fd(sz);
 +
    j--;
 +
    if (j<=0) {
 +
      j=ne;
 +
      i--;
 +
    }
 +
    var st = 'innerloop('+(i)+','+(j)+','+(ne)+','+(sz)+')';
 +
    setTimeout(st,speed);
 
   }
 
   }
 
}
 
}
  
t.cs();
+
function ngon(ne,sz) {
t.setProperty({strokeWidth:4,strokeOpacity:0.6,fillOpacity:0.3});
+
  innerloop(ne,ne,ne,sz);
t.hideTurtle();
+
}
mn_eck(36,20);
 
</textarea><br />
 
<input type="button" value="run" onClick="runturtle()">
 
<input type="button" value="clear" onClick="clearturtle()">
 
</form>
 
</html>
 
 
 
<jsxgraph width="600" height="600">
 
var brd = JXG.JSXGraph.initBoard('jxgbox', {originX:300, originY:300, unitX:1, unitY:1});
 
var t = brd.createElement('turtle',[],{fillColor:'yellow'});
 
  
 
function runturtle() {
 
function runturtle() {
   var code = $('inputtext').value;
+
   var code = document.getElementById('inputtext').value;
 
   if (code=='') { return; }
 
   if (code=='') { return; }
 
   eval(code);
 
   eval(code);
Line 37: Line 78:
 
   t.cs();
 
   t.cs();
 
}
 
}
//runturtle();
+
</source>
</jsxgraph>
+
 
 +
[[Category:Examples]]
 +
[[Category:Turtle Graphics]]

Latest revision as of 15:34, 3 March 2021



Sourcecode

var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-300, 300, 300, -300]});
var t = brd.create('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();
}