-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixjs.min.js
1 lines (1 loc) · 4.79 KB
/
matrixjs.min.js
1
!function(a){var b=function(b,c){return a.extend(this.values,c),this.el=b,this.init(),a.extend(b,this)};b.prototype={el:null,runsLeft:null,intervalId:null,values:{char:"",colors:[],characters:{},probabilities:{},height:"10",getRandom:function(){},interval:10},getChartype:function(){var a=this.values.getRandom();for(p in this.values.probabilities)if(a<=this.values.probabilities[p])return p},createChar:function(){var a=this.getChartype(),b=this.values.characters[a].length-1;return this.char=this.values.characters[a][this.values.getRandom(0,b)],this.char},init:function(){this.runs=this.values.getRandom(1,5),this.update(this.el);var a=this;a.intervalId=setInterval(function(){if(a.update(a.el),a.runs--,"undeined"==typeof a.runs||a.runs<=0)return void a.stop()},5)},update:function(a){a.text(this.createChar())},stop:function(){clearInterval(this.intervalId),this&&this.hasOwnProperty("parent")&&this.parent().childrent("span.bit").text(0)}};var c=function(b,c){return this.init(b,c),a.extend(b,this)};c.prototype={values:{range:5,delay:0,height:0,bitHeight:14,id:null},bits:{},intervalId:null,timerId:null,el:null,isRunning:!1,stop:function(){clearInterval(this.intervalId),this.children("span").css("color",this.values.colors.darkest).text(0),this.isRunning=!1},run:function(){var a=this;a.timerId=setTimeout(function(b){b.isRunning=!0,a.intervalId=setInterval(function(a){if(a.createBit(),a.isFull())return void a.stop()},a.values.getRandom(0,150),b)},a.delay,a)},init:function(b,c){this.values=a.extend(this.values,c),this.el=b},isFull:function(){var a="span.bit",b=this.children(a).length*this.values.bitHeight+this.values.bitHeight;return b>this.values.height},createBit:function(){var c=this;if(!c.isFull()){var d=a("<span>").addClass("bit").css("height",this.values.bitHeight);c.append(d);var e=new b(d,this.values),f=c.attr("id");c.bits[f]=c.bits[c.attr("id")]||[],c.bits[f].push(e);for(var g=c.bits[f].length,h=g<10?g:10,i=2;i<=h;i+=1)if("undefined"!=typeof c.bits[f][g-i])switch(i){case 1:case 2:case 3:case 4:c.bits[f][g-i].css("color",this.values.colors.light);break;case 5:case 6:case 7:c.bits[f][g-i].css("color",this.values.colors.med);break;case 8:c.bits[f][g-i].css("color",this.values.colors.dark);break;case 9:case 10:c.bits[f][g-i].css("color",this.values.colors.darkest)}}}};var d=function(b,c){if(a.extend(this.values,c),this.hasValidOptions())return this.init(b),this.enterTheMatrix(),b};d.prototype={values:{colors:{darkest:"#36ba01",dark:"#009a22",med:"#00ff2b",light:"#aaff2b",lightest:"#ddffaa"},characters:{hiragana:["あ","い","う","え","お","つ","て","と","な","ぬ","の","は","ひ","へ","ま","む","も","や","ゆ","よ","り","れ","ゎ","ゐ","を"],numbers:[1,2,3,4,5,6,7,8,9,0],letters:["a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z"],kanjis:["強","三","上","二","休","何","元","免","金","早","最","勉","ー","十","士","水","火","災","魚","黒","空","中","川","犬","木","安","花","強","文","村","人","車","内","元","刊","タ","子","市","千","手"]},probabilities:{hiragana:27,numbers:47,letters:70,kanjis:100},density:"normal",size:"fullScreen"},hasValidOptions:function(){var b=["characters","colors","probabilities"],c=[],d=!0;for(var e in b)a.isEmptyObject(this.values[b[e]])&&(c.push("This plugin requires to have "+b[e]+" set!"),d=!1);return d||alert(c.join("\n")),d},columns:[],densities:{normal:15,high:10,low:20},init:function(b){a.extend(this,b),this.values.hiraganaCount=this.values.characters.hiragana.length,this.values.numbersCount=this.values.characters.numbers.length,this.values.ettersCount=this.values.characters.letters.length,this.values.kanjisCount=this.values.characters.kanjis.length,this.values.density=this.densities[this.values.density]||15,this.values.size="string"==typeof this.values.size?this.values.size.split("x"):"fullScreen";var c=this;this.each(function(){"object"==typeof size&&size.length>0&&size[0]>0&&size[1]>0?(c.css("width",size[0]),c.css("height",size[1])):c.addClass("matrix fullScreen"),c.css("background-color","#000"),c.createColumns(c.css("width").replace("px",""),c.css("height").replace("px",""))})},enterTheMatrix:function(){for(var a in this.columns)this.columns[a].isRunning||this.columns[a].run()},createColumns:function(b,d){for(var e=Math.floor(b/this.values.density,0),f=0;f<e-1;f+=1){var g=a("<div>").attr("id","matrix-col-"+f).addClass("matrix-column").css("width",this.values.density+"px").data("index",f);this.append(g);var h=new c(g,a.extend({delay:this.getRandom(0,50),height:d,getRandom:this.getRandom,id:f},this.values));this.columns.push(h)}},getRandom:function(a,b){return a=a||0,b=b||100,Math.floor(Math.random()*(b-a+a))}},a.fn.matrix=function(a){this.matrix=new d(this.first(),a)}}(jQuery);