daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class snow {
  2.     constructor () {
  3.         this.x=Math.random()*1200;
  4.         this.y=Math.random()*600;
  5.         this.size = 10;
  6.     }
  7.    
  8.     drawSnowflake() {
  9.         for(let i = 0; i<200; i++) {
  10.         ctx.translate(this.x, this.y);
  11.         for(let i=0; i<8; i++) {
  12.             ctx.moveTo(0,0);
  13.             ctx.lineTo(this.size,0);
  14.             ctx.rotate(Math.PI*2/8);
  15.         }
  16.         ctx.strokeStyle = 'white';
  17.         ctx.stroke();
  18.         }
  19.     }
  20.  
  21.  
  22.     drawFlake() {
  23.         ctx.beginPath();
  24.         ctx.moveTo(this.x,this.y);
  25.         ctx.lineTo(this.x,this.y+1);
  26.         ctx.lineTo(this.x+1,this.y);
  27.         ctx.strokeStyle = '#fff';
  28.         ctx.stroke();
  29.         ctx.closePath();
  30.     }
  31.    
  32.     nextStep() {
  33.         this.y+=1;
  34.     }
  35.  
  36. }
  37.  
  38.     var snowFlakes = [];
  39.  
  40.     for(var i=0; i<200; i++) {
  41.         snowFlakes[i] = new snow();
  42.     }
  43.    
  44.  
  45. function drawSnowFlakes() {
  46.     ctx.clearRect(0,0,1200,600);
  47.  
  48.     for(var i=0; i<200; i++) {
  49.         snowFlakes[i].drawFlake();
  50.         snowFlakes[i].nextStep();
  51.  
  52.         if(snowFlakes[i].y>600) {
  53.             delete snowFlakes[i];
  54.             snowFlakes[i] = new snow();
  55.         }
  56.     }
  57. }
  58. var s = new snow();
  59. s.drawSnowflake();
  60. //setInterval(drawSnowFlakes,1);
  61. //s = new snow();
  62. //s.drawFlake();
  63. console.log(snowFlakes);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top