Sierpinski curve: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 42: | Line 42: | ||
</html> | </html> | ||
<jsxgraph width="600" height="600" box="box"> | <jsxgraph width="600" height="600" box="box"> | ||
var brd = JXG.JSXGraph.initBoard('box', { | var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]}); | ||
var t = brd. | var t = brd.create('turtle'); | ||
function run() { | function run() { | ||
brd.suspendUpdate(); | brd.suspendUpdate(); |
Latest revision as of 13:34, 8 June 2011
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);