Użytkownik:Michał56/monobook.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M Znacznik: edytor źródłowy |
M Znacznik: edytor źródłowy |
||
Linia 1: | Linia 1: | ||
//śnieg |
|||
//szybki link do statów |
|||
// KOD NA ŚNIEG |
|||
//$('#p-cactions > .pBody > ul').append('<li id="ca-qs"><a href="/wiki/Nonsensopedia:Statystyki dzień po dniu?action=edit" id="ca-qs-link">Uzupełnij staty</a></li>'); |
|||
(function() { |
|||
'use strict'; |
|||
//gówniak |
|||
var NUM_FLAKES = 40; |
|||
snow_img = 'http://wstaw.org/m/2016/12/21/snowflake-grey-hi.png'; |
|||
var flakes, Flake, PI_2, canvas, context, drawCircle, i, range, resizeWindow, xpos; |
|||
snow_no = 15; |
|||
PI_2 = 2 * Math.PI; |
|||
if (typeof(window.pageYOffset) == "number") |
|||
canvas = $('<canvas style="z-index: 500; pointer-events: none; position: fixed; top: 0; left: 0;" id="snieg"></canvas>').appendTo("body")[0]; |
|||
{ |
|||
context = canvas.getContext("2d"); |
|||
snow_browser_width = window.innerWidth; |
|||
window.w = 0; |
|||
window.h = 0; |
|||
} |
|||
resizeWindow = function() { |
|||
else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) |
|||
window.w = canvas.width = window.innerWidth; |
|||
{ |
|||
return (window.h = canvas.height = window.innerHeight); |
|||
snow_browser_width = document.body.offsetWidth; |
|||
}; |
|||
snow_browser_height = document.body.offsetHeight; |
|||
window.addEventListener('resize', resizeWindow, false); |
|||
} |
|||
$(function() {return setTimeout(resizeWindow, 0);}); |
|||
else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) |
|||
range = function(a, b) {return (b - a) * Math.random() + a;}; |
|||
{ |
|||
drawCircle = function(x, y, r) { |
|||
snow_browser_width = document.documentElement.offsetWidth; |
|||
context.beginPath(); |
|||
snow_browser_height = document.documentElement.offsetHeight; |
|||
context.arc(x, y, r, 0, PI_2, false); |
|||
} |
|||
context.fill(); |
|||
else |
|||
context.stroke(); |
|||
{ |
|||
}; |
|||
snow_browser_width = 500; |
|||
xpos = 0.5; |
|||
snow_browser_height = 500; |
|||
document.onmousemove = function(e) {return (xpos = e.pageX / w);}; |
|||
} |
|||
window.requestAnimationFrame = (function() { |
|||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { |
|||
snow_dx = []; |
|||
return window.setTimeout(callback, 1000 / 60); |
|||
snow_xp = []; |
|||
}; |
|||
snow_yp = []; |
|||
})(); |
|||
snow_am = []; |
|||
Flake = (function() { |
|||
snow_stx = []; |
|||
function Flake() { |
|||
snow_sty = []; |
|||
this.r = ~~range(4, 8); |
|||
this.r2 = 2 * this.r; |
|||
for (i = 0; i < snow_no; i++) |
|||
this.replace(); |
|||
{ |
|||
} |
|||
snow_dx[i] = 0; |
|||
Flake.prototype.replace = function() { |
|||
snow_xp[i] = Math.random()*(snow_browser_width-50); |
|||
this.x = range(-this.r2, w - this.r2); |
|||
snow_yp[i] = Math.random()*snow_browser_height; |
|||
this.y = range(-20, h - this.r2); |
|||
snow_am[i] = Math.random()*20; |
|||
this.xmax = w - this.r; |
|||
snow_stx[i] = 0.02 + Math.random()/10; |
|||
this.ymax = h - this.r; |
|||
snow_sty[i] = 0.7 + Math.random(); |
|||
this.vx = range(0, 2) + 8 * xpos - 5; |
|||
if (i > 0) document.write("<\div id=\"snow_flake"+ i +"\" style=\"position:absolute;z-index:"+i+"\"><\img src=\""+snow_img+"\" border=\"0\"><\/div>"); else document.write("<\div id=\"snow_flake0\" style=\"position:absolute;z-index:0\"><a href=\"http://peters1.dk/tools/snow.php\" target=\"_blank\"><\img src=\""+snow_img+"\" border=\"0\"></a><\/div>"); |
|||
this.vy = 0.7 * this.r + range(-1, 1); |
|||
} |
|||
}; |
|||
Flake.prototype.draw = function() { |
|||
function SnowStart() |
|||
var f; |
|||
{ |
|||
this.x += this.vx; |
|||
for (i = 0; i < snow_no; i++) |
|||
this.y += this.vy; |
|||
{ |
|||
if (this.y > this.ymax) { |
|||
snow_yp[i] += snow_sty[i]; |
|||
this.replace(); |
|||
if (snow_yp[i] > snow_browser_height-50) |
|||
} |
|||
{ |
|||
if (!((0 < (f = this.x) && f < this.xmax))) { |
|||
snow_xp[i] = Math.random()*(snow_browser_width-snow_am[i]-30); |
|||
this.x = (this.x + this.xmax) % this.xmax; |
|||
snow_yp[i] = 0; |
|||
} |
|||
snow_stx[i] = 0.02 + Math.random()/10; |
|||
drawCircle(~~this.x, ~~this.y, this.r); |
|||
snow_sty[i] = 0.7 + Math.random(); |
|||
}; |
|||
} |
|||
return Flake; |
|||
snow_dx[i] += snow_stx[i]; |
|||
})(); |
|||
document.getElementById("snow_flake"+i).style.top=snow_yp[i]+"px"; |
|||
flakes = (function() { |
|||
document.getElementById("snow_flake"+i).style.left=snow_xp[i] + snow_am[i]*Math.sin(snow_dx[i])+"px"; |
|||
var i, a = []; |
|||
} |
|||
for (i = 0; i < NUM_FLAKES; i++) |
|||
snow_time = setTimeout("SnowStart()", 10); |
|||
a.push(new Flake()); |
|||
} |
|||
return a; |
|||
SnowStart(); |
|||
})(); |
|||
window.step = function() { |
|||
var i, len; |
|||
requestAnimationFrame(step); |
|||
context.clearRect(0, 0, w, h); |
|||
context.fillStyle = "rgba(255,255,255,1)"; |
|||
context.lineWidth = 2; |
|||
context.strokeStyle = "rgba(0,0,0,0.25)"; |
|||
for (i = 0, len = flakes.length; i < len; i++) |
|||
flakes[i].draw(); |
|||
}; |
|||
step(); |
|||
console.log("Załadowano śnieg"); |
|||
})(); |
Wersja z 23:13, 21 gru 2016
//śnieg
// KOD NA ŚNIEG
(function() {
'use strict';
var NUM_FLAKES = 40;
var flakes, Flake, PI_2, canvas, context, drawCircle, i, range, resizeWindow, xpos;
PI_2 = 2 * Math.PI;
canvas = $('<canvas style="z-index: 500; pointer-events: none; position: fixed; top: 0; left: 0;" id="snieg"></canvas>').appendTo("body")[0];
context = canvas.getContext("2d");
window.w = 0;
window.h = 0;
resizeWindow = function() {
window.w = canvas.width = window.innerWidth;
return (window.h = canvas.height = window.innerHeight);
};
window.addEventListener('resize', resizeWindow, false);
$(function() {return setTimeout(resizeWindow, 0);});
range = function(a, b) {return (b - a) * Math.random() + a;};
drawCircle = function(x, y, r) {
context.beginPath();
context.arc(x, y, r, 0, PI_2, false);
context.fill();
context.stroke();
};
xpos = 0.5;
document.onmousemove = function(e) {return (xpos = e.pageX / w);};
window.requestAnimationFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
return window.setTimeout(callback, 1000 / 60);
};
})();
Flake = (function() {
function Flake() {
this.r = ~~range(4, 8);
this.r2 = 2 * this.r;
this.replace();
}
Flake.prototype.replace = function() {
this.x = range(-this.r2, w - this.r2);
this.y = range(-20, h - this.r2);
this.xmax = w - this.r;
this.ymax = h - this.r;
this.vx = range(0, 2) + 8 * xpos - 5;
this.vy = 0.7 * this.r + range(-1, 1);
};
Flake.prototype.draw = function() {
var f;
this.x += this.vx;
this.y += this.vy;
if (this.y > this.ymax) {
this.replace();
}
if (!((0 < (f = this.x) && f < this.xmax))) {
this.x = (this.x + this.xmax) % this.xmax;
}
drawCircle(~~this.x, ~~this.y, this.r);
};
return Flake;
})();
flakes = (function() {
var i, a = [];
for (i = 0; i < NUM_FLAKES; i++)
a.push(new Flake());
return a;
})();
window.step = function() {
var i, len;
requestAnimationFrame(step);
context.clearRect(0, 0, w, h);
context.fillStyle = "rgba(255,255,255,1)";
context.lineWidth = 2;
context.strokeStyle = "rgba(0,0,0,0.25)";
for (i = 0, len = flakes.length; i < len; i++)
flakes[i].draw();
};
step();
console.log("Załadowano śnieg");
})();