Koch 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 koch(x,level) { | function koch(x,level) { | ||
Line 27: | Line 25: | ||
<input type="button" value="clear" onClick="clearturtle()"> | <input type="button" value="clear" onClick="clearturtle()"> | ||
</form> | </form> | ||
< | </html> | ||
<jsxgraph width="600" height="400" 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.create('turtle'); | var t = brd.create('turtle'); | ||
Line 42: | Line 40: | ||
} | } | ||
run(); | run(); | ||
</ | </jsxgraph> | ||
===References=== | ===References=== |
Revision as of 09:39, 25 March 2011
References
Source code
var brd = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 300, unitX: 1, unitY: 1});
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);