Mediawiki:common.js

Вернуться

Строка 1: Строка 1:
/* Снег */
(function(){
    var canvas = document.createElement('canvas');
    canvas.style.position = 'fixed';
    canvas.style.left = '0';
    canvas.style.top = '0';
    canvas.style.width = '100%';
    canvas.style.height = '100%';
    canvas.style.pointerEvents = 'none';
    canvas.style.zIndex = '9999';
    document.documentElement.appendChild(canvas);
    var ctx = canvas.getContext('2d');
    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 initFlakes(){
        flakes = [];
        var count = Math.max(40, Math.floor(w/25));
        for(var i=0;i<count;i++){
            flakes.push({
                x: rand(0,w),
                y: rand(-h,h),
                r: rand(0.7,2.4),
                vx: rand(-0.15,0.15),
                vy: rand(0.25,0.9),
                s: rand(0.5,1.5)
            });
        }
    }
    var raf = window.requestAnimationFrame || function(fn){ setTimeout(fn,16); };
    function loop(){
        t += 0.003;
        ctx.clearRect(0,0,w,h);
        ctx.beginPath();
        for(var i=0;i<flakes.length;i++){
            var f = flakes[i];
            f.x += f.vx + Math.cos(t+f.s)*0.2;
            f.y += f.vy + Math.sin(t+f.s)*0.1;
            if(f.y > h+10){ f.y = -10; f.x = rand(0,w); }
            if(f.x < -20 || f.x > w+20){ f.x = rand(0,w); f.y = -10; }
            ctx.moveTo(f.x,f.y);
            ctx.arc(f.x,f.y,f.r,0,6.283);
        }
        ctx.fillStyle = 'rgba(255,255,255,0.85)';
        ctx.fill();
        raf(loop);
    }
    window.addEventListener('resize', resize);
    resize();
    loop();
})();


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