Turtle snow fall: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 25: Line 25:
     });
     });
}
}
t.ht();
function snow() {
function snow() {
  counter++;
  if (counter>500) {
      counter = 0;
      t.cs();
  }
   t.setPos(Math.random()*600-300,Math.random()*600-300);
   t.setPos(Math.random()*600-300,Math.random()*600-300);
   snowflake(50*Math.random(),Math.floor(Math.random()*4));
   snowflake(50*Math.random(),Math.floor(Math.random()*4));
Line 32: Line 36:
}
}
t.setPenColor('#ffff00');
t.setPenColor('#ffff00');
t.ht();
counter = 0;
snow();
snow();
          
          
Line 84: Line 91:
t.ht();
t.ht();
function snow() {
function snow() {
  counter++;
  if (counter>500) {
      counter = 0;
      t.cs();
  }
   t.setPos(Math.random()*600-300,Math.random()*600-300);
   t.setPos(Math.random()*600-300,Math.random()*600-300);
   snowflake(30*Math.random(),Math.floor(Math.random()*4));
   snowflake(30*Math.random(),Math.floor(Math.random()*4));
Line 89: Line 101:
}
}
t.setPenColor('#ffff00');
t.setPenColor('#ffff00');
counter = 0;
snow();</source>
snow();</source>



Revision as of 10:15, 23 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() {
   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();