From e7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 10 Aug 2014 17:28:37 +0200 Subject: First version --- point/plugins/doge/doge.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 point/plugins/doge/doge.js (limited to 'point/plugins/doge/doge.js') diff --git a/point/plugins/doge/doge.js b/point/plugins/doge/doge.js new file mode 100644 index 0000000..692ec03 --- /dev/null +++ b/point/plugins/doge/doge.js @@ -0,0 +1,89 @@ +/* + * This file is part of "What's The Point" + * Copyright (C) 2014 Pacien TRAN-GIRARD + * + * "What's The Point" is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * "What's The Point" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +define([ "css!plugins/doge/doge" ], function () { + + var doge = { + + TAG: "d-doge", + NUMBER: 2, + INTERVAL: 4000, + MAX_SIZE: 2, + MIN_SIZE: 3, + WORD: [ "wow", "so slides", "many points", "very slideshow", "such clear", "much serious" ], + COLOURS: [ "red", "green", "orange", "violet", "aqua", "yellow", "slateblue", "purple", "pink", "lime", "fuchsia", "gold", "indigo" ], + + init: function () { + this.woofs = []; + this.c = 0; + setInterval(doge.spawn, this.INTERVAL); + }, + + getRandomFromInterval: function (min, max) { + return Math.random() * (max - min) + min; + }, + + getRandomFontSize: function () { + return doge.getRandomFromInterval(doge.MIN_SIZE, doge.MAX_SIZE); + }, + + getRandomItem: function (items) { + return items[Math.floor(Math.random() * items.length)]; + }, + + getRandomColour: function () { + return doge.getRandomItem(doge.COLOURS); + }, + + getRandomWord: function () { + return doge.getRandomItem(doge.WORD); + }, + + woof: function () { + var woof = document.createElement(doge.TAG); + + document.body.appendChild(woof); + doge.woofs.push(woof); + + woof.appendChild(document.createTextNode(doge.getRandomWord())); + + woof.style.animationDuration = doge.NUMBER * doge.INTERVAL + "ms"; + woof.style.WebkitAnimationDuration = woof.style.animationDuration; + + woof.style.fontSize = doge.getRandomFontSize() + "em"; + woof.style.color = doge.getRandomColour(); + + woof.style.top = doge.getRandomFromInterval(0, window.innerHeight - woof.offsetHeight) + "px"; + woof.style.left = doge.getRandomFromInterval(0, window.innerWidth - woof.offsetWidth) + "px"; + + }, + + spawn: function () { + if (doge.woofs.length >= doge.NUMBER) { + doge.woofs[0].remove(); + doge.woofs.splice(0, 1); + } + + doge.woof(); + }, + + }; + + return doge; + +}); -- cgit v1.2.3