Sierpinski curve

From JSXGraph Wiki
Revision as of 17:27, 29 October 2009 by A WASSERMANN (talk | contribs)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


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();
level = 3;
t.setPos(0,-300);
sierpinski(150/Math.pow(2,level),level);