Difference between revisions of "Turtle snow fall"

From JSXGraph Wiki
Jump to navigationJump to search
Line 1: Line 1:
 
<html>
 
<html>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
 
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
 
<form><textarea id="inputtext" rows=3 cols=35 wrap="off" style="width:600px;">
 
function side(size, level) {
 
function side(size, level) {
Line 43: Line 41:
 
<input type="button" value="clear" onClick="clearturtle()">
 
<input type="button" value="clear" onClick="clearturtle()">
 
</form>
 
</form>
<div id="box" class="jxgbox" style="width:600px; height:600px;background-color:#000000"></div>
+
</html>
<script language="JavaScript">
+
<jsxgraph width="600" height="600" box="box">
 +
document.getElementById('box').style.backgroundColor = 'black';
 
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.createElement('turtle');
+
var t = brd.create('turtle');
 
function run() {
 
function run() {
 
   brd.suspendUpdate();
 
   brd.suspendUpdate();
Line 59: Line 58:
 
}
 
}
 
run();
 
run();
</script>
+
</jsxgraph>
</html>
 
  
 
===References===
 
===References===

Revision as of 11:07, 25 March 2011


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) {
    for (var i=0; i<3; i++) {
        side(size, level);
        t.rt(120);
    }
}
t.ht();
function snow() {
   counter++;
   if (counter>500) {
      counter = 0;
      t.cs();
   }
   t.setPos(Math.random()*600-300,Math.random()*600-300);
   snowflake(30*Math.random(),Math.floor(Math.random()*4));
   active = setTimeout(snow,200);
}
t.setPenColor('#ffff00');
counter = 0;
snow();