Mediawiki:common.js

Вернуться

Строка 9: Строка 9:
     canvas.style.pointerEvents = 'none';
     canvas.style.pointerEvents = 'none';
     canvas.style.zIndex = '9999';
     canvas.style.zIndex = '9999';
     document.documentElement.appendChild(canvas);
     document.body.appendChild(canvas);


     var ctx = canvas.getContext('2d');
     var ctx = canvas.getContext('2d');
     var w = 0, h = 0, flakes = [], t = 0;
     var w = 0, h = 0, flakes = [], t = 0;
    function resize(){
        w = canvas.width = window.innerWidth;
        h = canvas.height = window.innerHeight;
        initFlakes();
    }


     function rand(a,b){ return Math.random()*(b-a)+a; }
     function rand(a,b){ return Math.random()*(b-a)+a; }
Строка 24: Строка 18:
     function initFlakes(){
     function initFlakes(){
         flakes = [];
         flakes = [];
         var count = Math.max(40, Math.floor(w/25));
         var count = Math.max(40, Math.floor(w/20));
         for(var i=0;i<count;i++){
         for(var i=0; i<count; i++){
             flakes.push({
             flakes.push({
                 x: rand(0,w),
                 x: rand(0,w),
                 y: rand(-h,h),
                 y: rand(-h,h),
                 r: rand(0.7,2.4),
                 r: rand(1,4),
                 vx: rand(-0.15,0.15),
                 vx: rand(-0.3,0.3),
                 vy: rand(0.25,0.9),
                 vy: rand(0.5,1.2),
                 s: rand(0.5,1.5)
                swing: rand(0,Math.PI*2),
                 swingSpeed: rand(0.01,0.03)
             });
             });
         }
         }
    }
    function resize(){
        w = canvas.width = window.innerWidth;
        h = canvas.height = window.innerHeight;
        initFlakes();
     }
     }


Строка 40: Строка 41:


     function loop(){
     function loop(){
         t += 0.003;
         t += 0.01;
         ctx.clearRect(0,0,w,h);
         ctx.clearRect(0,0,w,h);
        ctx.fillStyle = 'rgba(255,255,255,0.85)';
         ctx.beginPath();
         ctx.beginPath();
         for(var i=0;i<flakes.length;i++){
         for(var i=0; i<flakes.length; i++){
             var f = flakes[i];
             var f = flakes[i];
             f.x += f.vx + Math.cos(t+f.s)*0.2;
            f.swing += f.swingSpeed;
             f.y += f.vy + Math.sin(t+f.s)*0.1;
             f.x += f.vx + Math.sin(f.swing)*0.5;
             if(f.y > h+10){ f.y = -10; f.x = rand(0,w); }
             f.y += f.vy;
             if(f.x < -20 || f.x > w+20){ f.x = rand(0,w); f.y = -10; }
 
             if(f.y > h + 5){
                f.y = -5;
                f.x = rand(0,w);
            }
             if(f.x < -10) f.x = w+10;
            if(f.x > w+10) f.x = -10;


             ctx.moveTo(f.x,f.y);
             ctx.moveTo(f.x,f.y);
             ctx.arc(f.x,f.y,f.r,0,6.283);
             ctx.arc(f.x,f.y,f.r,0,2*Math.PI);
         }
         }
        ctx.fillStyle = 'rgba(255,255,255,0.85)';
         ctx.fill();
         ctx.fill();
         raf(loop);
         raf(loop);
Строка 62: Строка 69:
     loop();
     loop();
})();
})();


/* Аудиоплееры */
/* Аудиоплееры */