Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class snow {
- constructor () {
- this.x=Math.random()*1200;
- this.y=Math.random()*600;
- this.size = 10;
- }
- drawSnowflake() {
- for(let i = 0; i<200; i++) {
- ctx.translate(this.x, this.y);
- for(let i=0; i<8; i++) {
- ctx.moveTo(0,0);
- ctx.lineTo(this.size,0);
- ctx.rotate(Math.PI*2/8);
- }
- ctx.strokeStyle = 'white';
- ctx.stroke();
- }
- }
- drawFlake() {
- ctx.beginPath();
- ctx.moveTo(this.x,this.y);
- ctx.lineTo(this.x,this.y+1);
- ctx.lineTo(this.x+1,this.y);
- ctx.strokeStyle = '#fff';
- ctx.stroke();
- ctx.closePath();
- }
- nextStep() {
- this.y+=1;
- }
- }
- var snowFlakes = [];
- for(var i=0; i<200; i++) {
- snowFlakes[i] = new snow();
- }
- function drawSnowFlakes() {
- ctx.clearRect(0,0,1200,600);
- for(var i=0; i<200; i++) {
- snowFlakes[i].drawFlake();
- snowFlakes[i].nextStep();
- if(snowFlakes[i].y>600) {
- delete snowFlakes[i];
- snowFlakes[i] = new snow();
- }
- }
- }
- var s = new snow();
- s.drawSnowflake();
- //setInterval(drawSnowFlakes,1);
- //s = new snow();
- //s.drawFlake();
- console.log(snowFlakes);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement