This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var getImageNaturalSize = function(img){ | |
| var w = img.width, | |
| h = img.height, | |
| tw, th; // Temp | |
| if (typeof img.naturalWidth !== undefined) { // for Firefox, Safari, Chrome | |
| w = img.naturalWidth; | |
| h = img.naturalHeight; | |
| } else if (typeof img.runtimeStyle !== undefined) { // for IE | |
| var run = img.runtimeStyle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isImageLoaded(img) { | |
| if (!img.complete) return false; | |
| if (typeof img.naturalWidth !== 'undefined' && img.naturalWidth === 0) return false; | |
| return true; | |
| } | |
| function onImageLoaded(img, callback) { | |
| if (isImageLoaded(img)) callback.call(img); | |
| else img.addEventListener('load', callback, false); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Vector2d | |
| */ | |
| function Vector2d(x, y) { | |
| this.x = x || 0; | |
| this.y = y || 0; | |
| } | |
| Vector2d.add = function(a, b) { | |
| return new Vector2d(a.x + b.x, a.y + b.y); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var log = (function(c) { | |
| var limit = 1000, count = 0; | |
| function log() { | |
| if (limit) { if (limit === count) return; count++; } | |
| c.log.apply(c, arguments); | |
| return log; | |
| } | |
| log.limit = function(_limit) { limit = _limit < 0 ? 0 : _limit; return log; }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function printf(format) { | |
| var pattern; | |
| for (var i = 0, len = arguments.length - 1; i < len; i++) { | |
| pattern = new RegExp('\\{' + i + '\\}', 'g'); | |
| format = format.replace(pattern, arguments[i + 1]); | |
| } | |
| return format; | |
| } | |
| // printf('Hello {0}', 'World'); // Hello World |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Random = (function() { | |
| /** | |
| * Alea, Mash function | |
| * | |
| * @see http://baagoe.com/en/RandomMusings/javascript/ | |
| */ | |
| function Random() { | |
| var s0 = 0, s1 = 0, s2 = 0, c = 1; |