Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var im = new Image(),
- au, doneTurn,
- turnX, wid, hei, xDelta, yDelta,
- minXspd = 4, maxXspd = 8,
- maxYspd = 4, maxInus = 10,
- x, y;
- function newDeltas() {
- xDelta = Math.trunc(Math.random() * (maxXspd - minXspd)) + minXspd;
- yDelta = Math.trunc(Math.random() * ((maxYspd * 2) + 1)) - maxYspd;
- }
- function newMods() {
- doneTurn = false;
- turnX = Math.trunc(Math.random() * innerWidth)-wid;
- newDeltas();
- x = innerWidth;
- y = Math.trunc(Math.random() * (innerHeight + hei)) - hei;
- }
- window.inus = window.inus || 0;
- if(window.inus >= maxInus) return;
- if(!window.inus) {
- au = new Audio("https://omfgdogs.com/omfgdogs.mp3");
- }
- window.inus++;
- im.src = "http://i.imgur.com/ZgDxHDF.gif";
- im.style.cssText = "position:absolute;visibility:hidden;left:" + x + "px;top:" + y + "px";
- im.onload = function() {
- wid = im.width;
- hei = im.height;
- newMods();
- im.style.visibility = "";
- if(au) {
- au.loop = true;
- au.play();
- }
- setInterval(function() {
- x -= xDelta;
- y -= yDelta;
- if ((x < -wid) || (y < -hei) || (y > innerHeight)) {
- newMods();
- } else if (!doneTurn && (x <= turnX)) {
- doneTurn = true;
- newDeltas();
- }
- im.style.left = x + "px";
- im.style.top = y + "px";
- }, 25);
- };
- document.body.appendChild(im);
- })()
Add Comment
Please, Sign In to add comment