Difference between revisions of "Sierpinski curve"

From JSXGraph Wiki
Jump to navigationJump to search
(New page: <html> <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/pro...)
 
Line 37: Line 37:
 
t.cs();
 
t.cs();
 
t.ht();
 
t.ht();
r = 4;
+
level = 3;
 
t.setPos(0,-300);
 
t.setPos(0,-300);
sierpinski(150/Math.pow(2,r),r);
+
sierpinski(150/Math.pow(2,level),level);
 
</textarea><br />
 
</textarea><br />
 
<input type="button" value="run" onClick="run()">
 
<input type="button" value="run" onClick="run()">

Revision as of 22:08, 22 December 2008


References

The source code

function halfSierpinski(s,l) {
    if (l==0) {
       t.fd(s);
    } else {
        halfSierpinski(s,l-1);
        t.lt(45);
        t.fd(s*Math.sqrt(2));
        t.lt(45);
        halfSierpinski(s,l-1);
        t.rt(90);
        t.fd(s);
        t.rt(90);
        halfSierpinski(s,l-1);
        t.lt(45);
        t.fd(s*Math.sqrt(2));
        t.lt(45);
        halfSierpinski(s,l-1);
    }
}

function sierpinski(s,l) {
    halfSierpinski(s,l);
    t.rt(90);
    t.fd(s);
    t.rt(90);
    halfSierpinski(s,l);
    t.rt(90);
    t.fd(s);
    t.rt(90);
}
t.cs();
t.ht();
r = 4;
t.setPos(0,-300);
sierpinski(150/Math.pow(2,r),r);