Sierpinski curve: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<html> | <html> | ||
<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;"> | ||
function halfSierpinski(s,l) { | function halfSierpinski(s,l) { | ||
Line 42: | Line 40: | ||
<input type="button" value="clear" onClick="clearturtle()"> | <input type="button" value="clear" onClick="clearturtle()"> | ||
</form> | </form> | ||
< | </html> | ||
<jsxgraph width="600" height="600" box="box"> | |||
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1}); | var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1}); | ||
var t = brd.createElement('turtle'); | var t = brd.createElement('turtle'); | ||
Line 57: | Line 55: | ||
} | } | ||
run(); | run(); | ||
</ | </jsxgraph> | ||
===References=== | ===References=== |
Revision as of 09:59, 25 March 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);