Sierpinski curve: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
No edit summary |
||
(8 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
<html> | <html> | ||
<form><textarea id="inputtext" rows=10 cols=35 wrap="off" style="width:600px;"> | |||
<form><textarea id="inputtext" rows= | |||
function halfSierpinski(s,l) { | function halfSierpinski(s,l) { | ||
if (l==0) { | if (l==0) { | ||
Line 44: | 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', { | var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -300]}); | ||
var t = | var t = brd.create('turtle'); | ||
function run() { | function run() { | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
var code = | var code = document.getElementById('inputtext').value; | ||
if (code=='') { return; } | if (code=='') { return; } | ||
eval(code); | eval(code); | ||
Line 56: | Line 52: | ||
} | } | ||
function clearturtle() { | function clearturtle() { | ||
t.cs(); | t.cs(); | ||
} | } | ||
run(); | run(); | ||
</ | </jsxgraph> | ||
===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=== | ||
Line 100: | Line 94: | ||
t.cs(); | t.cs(); | ||
t.ht(); | t.ht(); | ||
level = 3; | |||
t.setPos(0,-300); | t.setPos(0,-300); | ||
sierpinski(150/Math.pow(2, | sierpinski(150/Math.pow(2,level),level); | ||
</source> | </source> | ||
Line 108: | Line 102: | ||
[[Category:Turtle Graphics]] | [[Category:Turtle Graphics]] | ||
[[Category:Fractals]] | [[Category:Fractals]] | ||
[[Category:Curves]] |
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);