Difference between revisions of "Koch curve"
From JSXGraph Wiki
Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
|||
(16 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<html> | <html> | ||
− | + | <form><textarea id="inputtext" rows=10 cols=35 wrap="off" style="width:600px;"> | |
− | + | function koch(x,level) { | |
− | + | if (level<1) { | |
− | |||
− | <form><textarea id="inputtext" rows= | ||
− | function koch(x) { | ||
− | if ( | ||
t.fd(x); | t.fd(x); | ||
} else { | } else { | ||
− | koch(x/3); | + | koch(x/3,level-1); |
t.lt(60); | t.lt(60); | ||
− | koch(x/3); | + | koch(x/3,level-1); |
t.rt(120); | t.rt(120); | ||
− | koch(x/3); | + | koch(x/3,level-1); |
t.lt(60); | t.lt(60); | ||
− | koch(x/3); | + | koch(x/3,level-1); |
} | } | ||
} | } | ||
Line 23: | Line 19: | ||
t.setPos(-250,0); | t.setPos(-250,0); | ||
t.rt(90); | t.rt(90); | ||
− | koch(400); | + | koch(400,7); |
</textarea><br /> | </textarea><br /> | ||
Line 30: | Line 26: | ||
</form> | </form> | ||
</html> | </html> | ||
− | + | <jsxgraph width="600" height="400" box="box"> | |
− | < | + | var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -100]}); |
− | + | var t = brd.create('turtle'); | |
− | |||
− | var brd = JXG.JSXGraph.initBoard('box', { | ||
− | var t = | ||
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 47: | Line 40: | ||
} | } | ||
run(); | run(); | ||
− | </ | + | </jsxgraph> |
− | |||
===References=== | ===References=== | ||
− | + | * [http://www.mathcurve.com/fractals/koch/koch.shtml http://www.mathcurve.com/fractals/koch/koch.shtml] | |
− | * [http:// | + | |
+ | ===Source code=== | ||
+ | <source lang="javascript"> | ||
+ | var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -100]}); | ||
+ | var t = brd.create('turtle'); | ||
+ | function run() { | ||
+ | brd.suspendUpdate(); | ||
+ | var code = document.getElementById('inputtext').value; | ||
+ | if (code=='') { return; } | ||
+ | eval(code); | ||
+ | brd.unsuspendUpdate(); | ||
+ | } | ||
+ | function clearturtle() { | ||
+ | t.cs(); | ||
+ | } | ||
+ | run(); | ||
+ | |||
+ | function koch(x,level) { | ||
+ | if (level<1) { | ||
+ | t.fd(x); | ||
+ | } else { | ||
+ | koch(x/3,level-1); | ||
+ | |||
+ | t.lt(60); | ||
+ | koch(x/3,level-1); | ||
+ | t.rt(120); | ||
+ | koch(x/3,level-1); | ||
+ | t.lt(60); | ||
+ | koch(x/3,level-1); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | t.cs(); | ||
+ | t.hideTurtle(); | ||
+ | t.setPos(-250,0); | ||
+ | t.rt(90); | ||
+ | koch(400,7); | ||
+ | </source> | ||
[[Category:Examples]] | [[Category:Examples]] | ||
+ | |||
[[Category:Turtle Graphics]] | [[Category:Turtle Graphics]] | ||
[[Category:Fractals]] | [[Category:Fractals]] | ||
+ | [[Category:Curves]] |
Latest revision as of 09:58, 8 June 2011
References
Source code
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -100]});
var t = brd.create('turtle');
function run() {
brd.suspendUpdate();
var code = document.getElementById('inputtext').value;
if (code=='') { return; }
eval(code);
brd.unsuspendUpdate();
}
function clearturtle() {
t.cs();
}
run();
function koch(x,level) {
if (level<1) {
t.fd(x);
} else {
koch(x/3,level-1);
t.lt(60);
koch(x/3,level-1);
t.rt(120);
koch(x/3,level-1);
t.lt(60);
koch(x/3,level-1);
}
}
t.cs();
t.hideTurtle();
t.setPos(-250,0);
t.rt(90);
koch(400,7);