Sierpinski curve: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 64: Line 64:


===References===
===References===
* [http://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve]
* [http://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve http://en.wikipedia.org/wiki/Sierpi%C5%84ski_curve]


===The source code===
===The source code===

Revision as of 20: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);