Koch curve: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 4: Line 4:
<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=10 cols=35 wrap="off" style="width:600px;">
<form><textarea id="inputtext" rows=10 cols=35 wrap="off" style="width:600px;">
c = 0;
function koch(x,level) {
function koch(x,level) {
     if (level<1) {
     if (level<1) {
         t.fd(x);
         t.fd(x);
        c++;
     } else {
     } else {
         koch(x/3,level-1);
         koch(x/3,level-1);
Line 25: Line 23:
t.rt(90);
t.rt(90);
koch(400,7);
koch(400,7);
alert(c);
          
          
</textarea><br />
</textarea><br />

Revision as of 16:22, 25 March 2009


References

Source code

function koch(x,level) {
    if (level<1) {
        t.fd(x);
    } else {
        koch(x/3,level-1);
        t.lt(60);
        koch(x/3,level-1);
        t.rt(120);
        koch(x/3,level-1);
        t.lt(60);
        koch(x/3,level-1);
    }
}

t.cs();
t.hideTurtle();
t.setPos(-250,0);
t.rt(90);
koch(400,7);