Mediawiki:common.js
| Строка 1: | Строка 1: | ||
/* Снег */ | /* Снег */ | ||
(function(){ | (function(){ | ||
var canvas = document. | var canvas = document.querySelector('canvas'); | ||
if(!canvas) return; | |||
var ctx = canvas.getContext('2d'); | var ctx = canvas.getContext('2d'); | ||
var | var score = 0; | ||
var caughtFlakes = []; | |||
function | canvas.addEventListener('mousemove', function(e){ | ||
var mx = e.clientX; | |||
var my = e.clientY; | |||
for(var i=0;i<flakes.length;i++){ | |||
var f = flakes[i]; | |||
var dx = mx - f.x; | |||
var dy = my - f.y; | |||
if(Math.sqrt(dx*dx+dy*dy) < f.r*5){ | |||
caughtFlakes.push(f); | |||
score++; | |||
flakes[i] = {x: Math.random()*canvas.width, y: -10, r: f.r, vx: f.vx, vy: f.vy, s: f.s}; | |||
} | |||
} | |||
} | } | ||
} | }); | ||
var | var oldLoop = loop; | ||
loop = function(){ | |||
function | t += 0.003; | ||
t += 0. | ctx.clearRect(0,0,canvas.width,canvas.height); | ||
ctx.clearRect(0,0, | |||
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.x += f.vx + Math. | f.y += f.vy + Math.sin(t+f.s)*0.1; | ||
f.y += f.vy; | if(f.y > canvas.height+10){ f.y = -10; f.x = Math.random()*canvas.width; } | ||
if(f.x < -20 || f.x > canvas.width+20){ f.x = Math.random()*canvas.width; f.y = -10; } | |||
if(f.y > | |||
if(f.x < - | |||
ctx.moveTo(f.x,f.y); | ctx.moveTo(f.x,f.y); | ||
ctx.arc(f.x,f.y,f.r,0, | ctx.arc(f.x,f.y,f.r,0,6.283); | ||
} | } | ||
ctx.fillStyle = 'rgba(255,255,255,0.85)'; | |||
ctx.fill(); | ctx.fill(); | ||
ctx.font = "20px Arial"; | |||
ctx.fillStyle = "red"; | |||
ctx.fillText("Счёт: "+score, 10, 30); | |||
raf(loop); | raf(loop); | ||
} | }; | ||
})(); | |||