forked from AndrewRayCode/Bash-Prompt-Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mootools.noisy.min.js
1 lines (1 loc) · 2.12 KB
/
mootools.noisy.min.js
1
var Noisy=new Class({Implements:Options,options:{intensity:0.9,size:200,opacity:0.08,fallback:"",monochrome:false},initialize:function(b,a){b=this.element=document.id(b);if(!b){return false;}a&&this.setOptions(a);},noisify:function(e){var k=this.options,g=k.fallback,f=k.intensity,j=k.size,h=k.opacity;if(e!=undefined){e=this.getCachedUri(this.options);}if(!e){if(!this.hasCanvas()){e=this.options.fallback;}else{var d=this.getCanvas(),i=d.getContext("2d"),b,c=this.getPixelIntensity(f,j),a=this.getMaxAlpha(h);d.width=d.height=j;b=i.createImageData(j,j);this.randomizeImageData(b,c,a);e=d.toDataURL("image/png");if(e.indexOf("data:image/png")!=0||Browser.ie&&Browser.version<9&&e.length>32768){e=g;}}this.setCachedUri(k,e);}this.element.setStyle("background-image","url("+e+")");return this;},bitwiseRandomize:function(b){return ~~(Math.random()*b);},updateCanvas:function(c){var b=this.getCanvas(),a=b.getContext("2d");a.putImageData(c,0,0);return this;},randomizeImageData:function(b,c,a){var d=this.getCanvas(),j=d.getContext("2d"),h=this.options.monochrome;if(j){while(c--){var i=this.bitwiseRandomize(d.width),g=this.bitwiseRandomize(d.height),e=(i+g*b.width)*4,f=c%255;b.data[e]=f;b.data[e+1]=h?f:this.bitwiseRandomize(255);b.data[e+2]=h?f:this.bitwiseRandomize(255);b.data[e+3]=this.bitwiseRandomize(a);}this.updateCanvas(b);}return this;},getPixelIntensity:function(d,c){return d*Math.pow(c,2);},getMaxAlpha:function(b){return 255*b;},setCachedUri:function(a,b){this.hasLocalStorage()&&localStorage.setItem(JSON.encode(a),b);return this;},getCachedUri:function(a){return this.hasLocalStorage()?localStorage.getItem(JSON.encode(a)):false;},hasLocalStorage:function(){return !!localStorage;},setCanvas:function(){this.canvas=document.createElement("canvas");return this;},getCanvas:function(){var a=this.canvas;if(!a){this.setCanvas();a=this.canvas;}return a;},hasCanvas:function(){return !!this.getCanvas();}});Element.Properties.noisy={set:function(a){var b=this.get("noisy");b.setOptions(a);return this;},get:function(){var a=this.retrieve("noisy",new Noisy(this));return a;}};Element.implement({noisify:function(a){this.get("noisy").noisify(a);return this;}});