Koch curve: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 29: Line 29:
<input type="button" value="clear" onClick="clearturtle()">
<input type="button" value="clear" onClick="clearturtle()">
</form>
</form>
</html>
===Output===
<html>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
<div id="box" class="jxgbox" style="width:600px; height:600px;"></div>
<script language="JavaScript">
<script language="JavaScript">
Line 56: Line 53:
===Source code===
===Source code===
<source lang="javascript">
<source lang="javascript">
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>
</source>
[[Category:Examples]]
[[Category:Examples]]
[[Category:Turtle Graphics]]
[[Category:Turtle Graphics]]
[[Category:Fractals]]
[[Category:Fractals]]

Revision as of 15:04, 21 December 2008


References

This example is from

Source code

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);