Turtle snow fall: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary  | 
				A WASSERMANN (talk | contribs) No edit summary  | 
				||
| Line 59: | Line 59: | ||
* [http://www.mathcurve.com/fractals/koch/koch.shtml http://www.mathcurve.com/fractals/koch/koch.shtml]  | * [http://www.mathcurve.com/fractals/koch/koch.shtml http://www.mathcurve.com/fractals/koch/koch.shtml]  | ||
===The source code===  | |||
<source lang="javascript">  | |||
function side(size, level) {  | |||
    if (level==0) {  | |||
        t.fd(size);  | |||
    } else {  | |||
        side(size/3, level-1);  | |||
        t.lt(60);  | |||
        side(size/3, level-1);  | |||
        t.rt(120);  | |||
        side(size/3, level-1);  | |||
        t.lt(60);  | |||
        side(size/3, level-1);  | |||
    }  | |||
}  | |||
function snowflake(size, level) {  | |||
    (3).times(function() {  | |||
        side(size, level);  | |||
        t.rt(120);  | |||
    });  | |||
}  | |||
t.ht();  | |||
function snow() {  | |||
   t.setPos(Math.random()*600-300,Math.random()*600-300);  | |||
   snowflake(30*Math.random(),Math.floor(Math.random()*4));  | |||
   active = setTimeout(snow,50);  | |||
}  | |||
snow();</source>  | |||
[[Category:Examples]]  | [[Category:Examples]]  | ||
[[Category:Turtle Graphics]]  | [[Category:Turtle Graphics]]  | ||
[[Category:Fractals]]  | [[Category:Fractals]]  | ||
Revision as of 11:10, 22 December 2008
References
The source code
function side(size, level) {
    if (level==0) {
        t.fd(size);
    } else {
        side(size/3, level-1);
        t.lt(60);
        side(size/3, level-1);
        t.rt(120);
        side(size/3, level-1);
        t.lt(60);
        side(size/3, level-1);
    }
}
function snowflake(size, level) {
    (3).times(function() {
        side(size, level);
        t.rt(120);
    });
}
t.ht();
function snow() {
   t.setPos(Math.random()*600-300,Math.random()*600-300);
   snowflake(30*Math.random(),Math.floor(Math.random()*4));
   active = setTimeout(snow,50);
}
snow();