Koch curve: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
</html> | </html> | ||
<jsxgraph width="600" height="400" box="box"> | <jsxgraph width="600" height="400" box="box"> | ||
var brd = JXG.JSXGraph.initBoard('box', { | var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -100]}); | ||
var t = brd.create('turtle'); | var t = brd.create('turtle'); | ||
function run() { | function run() { | ||
Line 47: | Line 47: | ||
===Source code=== | ===Source code=== | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd = JXG.JSXGraph.initBoard('box', { | var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-300, 300, 300, -100]}); | ||
var t = brd.create('turtle'); | var t = brd.create('turtle'); | ||
function run() { | function run() { |
Latest revision as of 07: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);