-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.min.js
5 lines (5 loc) · 12.6 KB
/
matrix.min.js
1
2
3
4
5
/* MATRIX.js *
* Copyright (c) NullDev *
* github.com/NLDev/matrixjs *
* Licensed under MIT */
function get_random_int(a,_){return Math.floor(Math.random()*(_-a+1))+a}function get_random_spawn_x(){var a=get_random_int(0,mapW);if(1!=maxDropsINColumn&&matrixMap[a][mActive]&&1==get_random_int(0,2))for(var _=completedFromLeft;mapW>=_;++_)if(!matrixMap[_][mActive]){a=_,completedFromLeft=_;break}return a}function get_random_char(){var a=get_random_int(0,chrSetPow-1);return letters.slice(a,a+1)}function config_second_phase(){maxDropRdmArg=5,maxDropsINColumn=1,refreshDelay=33}function spawn_new_drop(){for(var a=get_random_spawn_x(),_=0;10!=_&&matrixMap[a][mDropsCount]>=maxDropsINColumn;++_)a=get_random_int(0,mapW);matrixMap[a][mDropsCount]<maxDropsINColumn&&(matrixMap[a][0][mType]=1,matrixMap[a][0][mPauseValue]=get_random_int(0,maxPause),matrixMap[a][0][mCurrentPause]=matrixMap[a][0][mPauseValue],matrixMap[a][0][mWhite]=250,matrixMap[a][0][mGreen]=0,matrixMap[a][0][mSymbol]=get_random_char(),matrixMap[a][0][mFade]=get_random_int(5,10),matrixMap[a][mDropsCount]++,matrixMap[a][mActive]=!0,matrixMap[a][mColumnUsed]||(matrixMap[a][mColumnUsed]=!0,matrixMap[mColumnUsedCount]++,matrixMap[mColumnUsedCount]>=mapW+1&&config_second_phase()))}function matrix(a){a=a.toLowerCase();var _=!1,t="",e="",r="",m="",n="",i="",o=" ",x=new Array(6),p=new Array(6),c=new Array(6),h=new Array(6),s=new Array(6),l=new Array(6),A=new Array(6),u=new Array(6),M=new Array(6),d=new Array(6),f=new Array(6),y=new Array(6),w=new Array(6),g=new Array(6),v=new Array(6),T=new Array(6),C=new Array(6),W=new Array(6),S=new Array(6),D=new Array(6),H=new Array(6),b=new Array(6),I=new Array(6),P=new Array(6),z=new Array(6),G=new Array(6),U=new Array(6),F=new Array(6),L=new Array(6),V=new Array(6),N=new Array(6),k=new Array(6),R=new Array(6),X=new Array(6),Y=new Array(6),j=new Array(6);x[0]=" ___ ",x[1]=" / | ",x[2]=" / /| | ",x[3]=" / / | | ",x[4]=" / / | | ",x[5]="/_/ |_| ",p[0]=" _____ ",p[1]="| _ \\ ",p[2]="| |_| | ",p[3]="| _ { ",p[4]="| |_| | ",p[5]="|_____/ ",c[0]=" _____ ",c[1]="/ ___| ",c[2]="| | ",c[3]="| | ",c[4]="| |___ ",c[5]="\\_____| ",h[0]=" _____ ",h[1]="| _ \\ ",h[2]="| | | | ",h[3]="| | | | ",h[4]="| |_| | ",h[5]="|_____/ ",s[0]=" _____ ",s[1]="| ____| ",s[2]="| |__ ",s[3]="| __| ",s[4]="| |___ ",s[5]="|_____| ",l[0]=" _____ ",l[1]="| ___| ",l[2]="| |__ ",l[3]="| __| ",l[4]="| | ",l[5]="|_| ",A[0]=" _____ ",A[1]="/ ___| ",A[2]="| | ",A[3]="| | _ ",A[4]="| |_| | ",A[5]="\\_____/ ",u[0]=" _ _ ",u[1]="| | | | ",u[2]="| |_| | ",u[3]="| _ | ",u[4]="| | | | ",u[5]="|_| |_| ",M[0]=" _ ",M[1]="| | ",M[2]="| | ",M[3]="| | ",M[4]="| | ",M[5]="|_| ",d[0]=" _ ",d[1]=" | | ",d[2]=" | | ",d[3]=" _ | | ",d[4]="| |_| | ",d[5]="\\_____/ ",f[0]=" _ _ ",f[1]="| | / / ",f[2]="| |/ / ",f[3]="| |\\ \\ ",f[4]="| | \\ \\ ",f[5]="|_| \\_\\ ",y[0]=" _ ",y[1]="| | ",y[2]="| | ",y[3]="| | ",y[4]="| |___ ",y[5]="|_____| ",w[0]=" ___ ___ ",w[1]=" / |/ | ",w[2]=" / /| /| | ",w[3]=" / / |__/ | | ",w[4]=" / / | | ",w[5]="/_/ |_| ",g[0]=" __ _ ",g[1]="| \\ | | ",g[2]="| \\| | ",g[3]="| |\\ | ",g[4]="| | \\ | ",g[5]="|_| \\_| ",v[0]=" _____ ",v[1]="/ _ \\ ",v[2]="| | | | ",v[3]="| | | | ",v[4]="| |_| | ",v[5]="\\_____/ ",T[0]=" _____ ",T[1]="| _ \\ ",T[2]="| |_| | ",T[3]="| ___/ ",T[4]="| | ",T[5]="|_| ",C[0]=" _____ ",C[1]="/ _ \\ ",C[2]="| | | | ",C[3]="| | | | ",C[4]="| |_| |_ ",C[5]="\\_______| ",W[0]=" _____ ",W[1]="| _ \\ ",W[2]="| |_| | ",W[3]="| _ / ",W[4]="| | \\ \\ ",W[5]="|_| \\_\\ ",S[0]=" _____ ",S[1]="/ ___/ ",S[2]="| |___ ",S[3]="\\___ \\ ",S[4]=" ___| | ",S[5]="/_____/ ",D[0]=" _____ ",D[1]="|_ _| ",D[2]=" | | ",D[3]=" | | ",D[4]=" | | ",D[5]=" |_| ",H[0]=" _ _ ",H[1]="| | | | ",H[2]="| | | | ",H[3]="| | | | ",H[4]="| |_| | ",H[5]="\\_____/ ",b[0]=" _ _ ",b[1]="| | / / ",b[2]="| | / / ",b[3]="| | / / ",b[4]="| |/ / ",b[5]="|___/ ",I[0]=" _ __ ",I[1]="| | / / ",I[2]="| | __ / / ",I[3]="| | / | / / ",I[4]="| |/ |/ / ",I[5]="|___/|___/ ",P[0]="__ __ ",P[1]="\\ \\ / / ",P[2]=" \\ \\/ / ",P[3]=" } { ",P[4]=" / /\\ \\ ",P[5]="/_/ \\_\\ ",z[0]="__ __ ",z[1]="\\ \\ / / ",z[2]=" \\ \\/ / ",z[3]=" \\ / ",z[4]=" / / ",z[5]=" /_/ ",G[0]=" ______ ",G[1]="|___ / ",G[2]=" / / ",G[3]=" / / ",G[4]=" / /__ ",G[5]="/_____| ",U[0]=" _____ ",U[1]="/ _ \\ ",U[2]="| | | | ",U[3]="| |/| | ",U[4]="| |_| | ",U[5]="\\_____/ ",F[0]=" ___ ",F[1]="|_ | ",F[2]=" | | ",F[3]=" | | ",F[4]=" | | ",F[5]=" |_| ",L[0]=" _____ ",L[1]="/___ \\ ",L[2]=" ___| | ",L[3]="/ ___/ ",L[4]="| |___ ",L[5]="|_____| ",V[0]=" _____ ",V[1]="|___ | ",V[2]=" _| | ",V[3]=" |_ { ",V[4]=" ___| | ",V[5]="|_____/ ",N[0]=" _ _ ",N[1]="| | | | ",N[2]="| |_| | ",N[3]="\\___ | ",N[4]=" | | ",N[5]=" |_| ",k[0]=" _____ ",k[1]="| ___| ",k[2]="| |___ ",k[3]="\\___ \\ ",k[4]=" ___| | ",k[5]="\\_____| ",R[0]=" _____ ",R[1]="/ ___| ",R[2]="| |___ ",R[3]="| _ \\ ",R[4]="| |_| | ",R[5]="\\_____/ ",X[0]=" _____ ",X[1]="|___ | ",X[2]=" / / ",X[3]=" / / ",X[4]=" / / ",X[5]=" /_/ ",Y[0]=" _____ ",Y[1]="/ _ \\ ",Y[2]="| |_| | ",Y[3]="} _ { ",Y[4]="| |_| | ",Y[5]="\\_____/ ",j[0]=" _____ ",j[1]="/ _ \\ ",j[2]="| |_| | ",j[3]="\\___ | ",j[4]=" ___| | ",j[5]="|_____/ ";for(var q=0;q<a.length;q++)if(" "==a.charAt(q)&&(t+=o,e+=o,r+=o,m+=o,n+=o,i+=o),"a"==a.charAt(q)&&(t+=x[0],e+=x[1],r+=x[2],m+=x[3],n+=x[4],i+=x[5]),"b"==a.charAt(q)&&(t+=p[0],e+=p[1],r+=p[2],m+=p[3],n+=p[4],i+=p[5]),"c"==a.charAt(q)&&(t+=c[0],e+=c[1],r+=c[2],m+=c[3],n+=c[4],i+=c[5]),"d"==a.charAt(q)&&(t+=h[0],e+=h[1],r+=h[2],m+=h[3],n+=h[4],i+=h[5]),"e"==a.charAt(q)&&(t+=s[0],e+=s[1],r+=s[2],m+=s[3],n+=s[4],i+=s[5]),"f"==a.charAt(q)&&(t+=l[0],e+=l[1],r+=l[2],m+=l[3],n+=l[4],i+=l[5]),"g"==a.charAt(q)&&(t+=A[0],e+=A[1],r+=A[2],m+=A[3],n+=A[4],i+=A[5]),"h"==a.charAt(q)&&(t+=u[0],e+=u[1],r+=u[2],m+=u[3],n+=u[4],i+=u[5]),"i"==a.charAt(q)&&(t+=M[0],e+=M[1],r+=M[2],m+=M[3],n+=M[4],i+=M[5]),"j"==a.charAt(q)&&(t+=d[0],e+=d[1],r+=d[2],m+=d[3],n+=d[4],i+=d[5]),"k"==a.charAt(q)&&(t+=f[0],e+=f[1],r+=f[2],m+=f[3],n+=f[4],i+=f[5]),"l"==a.charAt(q)&&(t+=y[0],e+=y[1],r+=y[2],m+=y[3],n+=y[4],i+=y[5]),"m"==a.charAt(q)&&(t+=w[0],e+=w[1],r+=w[2],m+=w[3],n+=w[4],i+=w[5]),"n"==a.charAt(q)&&(t+=g[0],e+=g[1],r+=g[2],m+=g[3],n+=g[4],i+=g[5]),"o"==a.charAt(q)&&(t+=v[0],e+=v[1],r+=v[2],m+=v[3],n+=v[4],i+=v[5]),"p"==a.charAt(q)&&(t+=T[0],e+=T[1],r+=T[2],m+=T[3],n+=T[4],i+=T[5]),"q"==a.charAt(q)&&(t+=C[0],e+=C[1],r+=C[2],m+=C[3],n+=C[4],i+=C[5]),"r"==a.charAt(q)&&(t+=W[0],e+=W[1],r+=W[2],m+=W[3],n+=W[4],i+=W[5]),"s"==a.charAt(q)&&(t+=S[0],e+=S[1],r+=S[2],m+=S[3],n+=S[4],i+=S[5]),"t"==a.charAt(q)&&(t+=D[0],e+=D[1],r+=D[2],m+=D[3],n+=D[4],i+=D[5]),"u"==a.charAt(q)&&(t+=H[0],e+=H[1],r+=H[2],m+=H[3],n+=H[4],i+=H[5]),"v"==a.charAt(q)&&(t+=b[0],e+=b[1],r+=b[2],m+=b[3],n+=b[4],i+=b[5]),"w"==a.charAt(q)&&(t+=I[0],e+=I[1],r+=I[2],m+=I[3],n+=I[4],i+=I[5]),"x"==a.charAt(q)&&(t+=P[0],e+=P[1],r+=P[2],m+=P[3],n+=P[4],i+=P[5]),"y"==a.charAt(q)&&(t+=z[0],e+=z[1],r+=z[2],m+=z[3],n+=z[4],i+=z[5]),"z"==a.charAt(q)&&(t+=G[0],e+=G[1],r+=G[2],m+=G[3],n+=G[4],i+=G[5]),"0"==a.charAt(q)&&(t+=U[0],e+=U[1],r+=U[2],m+=U[3],n+=U[4],i+=U[5]),"1"==a.charAt(q)&&(t+=F[0],e+=F[1],r+=F[2],m+=F[3],n+=F[4],i+=F[5]),"2"==a.charAt(q)&&(t+=L[0],e+=L[1],r+=L[2],m+=L[3],n+=L[4],i+=L[5]),"3"==a.charAt(q)&&(t+=V[0],e+=V[1],r+=V[2],m+=V[3],n+=V[4],i+=V[5]),"4"==a.charAt(q)&&(t+=N[0],e+=N[1],r+=N[2],m+=N[3],n+=N[4],i+=N[5]),"5"==a.charAt(q)&&(t+=k[0],e+=k[1],r+=k[2],m+=k[3],n+=k[4],i+=k[5]),"6"==a.charAt(q)&&(t+=R[0],e+=R[1],r+=R[2],m+=R[3],n+=R[4],i+=R[5]),"7"==a.charAt(q)&&(t+=X[0],e+=X[1],r+=X[2],m+=X[3],n+=X[4],i+=X[5]),"8"==a.charAt(q)&&(t+=Y[0],e+=Y[1],r+=Y[2],m+=Y[3],n+=Y[4],i+=Y[5]),"9"==a.charAt(q)&&(t+=j[0],e+=j[1],r+=j[2],m+=j[3],n+=j[4],i+=j[5]),"\\n"==a.substring(q,q+2)){_=!0;break}charText=[t,e,r,m,n,i],init()}function update(){for(var a=0;mapW>=a;++a)if(matrixMap[a][mActive]){for(var _=!1,t=0;mapH>=t;++t)if(0!=matrixMap[a][t][mType]){if(_=!0,matrixMap[a][t][mCurrentPause]>0){matrixMap[a][t][mCurrentPause]--;continue}switch(matrixMap[a][t][mCurrentPause]=matrixMap[a][t][mPauseValue],matrixMap[a][t][mType]){case 1:if(mapH>t&&!(matrixMap[a][t][mTextActive]&&" "!=matrixMap[a][t][mText]&&matrixMap[a][t][mText].length>0))for(var e in matrixMap[a][t])"mText"!=e&&"mTextActive"!=e&&(matrixMap[a][t+1][e]=matrixMap[a][t][e]);else matrixMap[a][mDropsCount]--;matrixMap[a][t][mSymbol]=get_random_char(),matrixMap[a][t][mType]=2,matrixMap[a][t][mCurrentPause]=matrixMap[a][t][mPauseValue],matrixMap[a][t][mWhite]=200,matrixMap[a][t][mGreen]=0,matrixMap[a][t][mTextActive]=!0,mapH>t&&t++;break;case 2:42==get_random_int(1,100)&&(matrixMap[a][t][mSymbol]=get_random_char()),matrixMap[a][t][mWhite]>150?(matrixMap[a][t][mWhite]-=50,matrixMap[a][t][mWhite]<=150&&(matrixMap[a][t][mWhite]=0,matrixMap[a][t][mGreen]=250)):matrixMap[a][t][mGreen]>0&&(matrixMap[a][t][mGreen]-=matrixMap[a][t][mFade],matrixMap[a][t][mGreen]<=0&&(matrixMap[a][t][mGreen]=0,matrixMap[a][t][mType]=0))}}_||(matrixMap[a][mActive]=!1)}1==get_random_int(1,maxDropRdmArg)&&spawn_new_drop()}function draw(){context.fillStyle="black",context.fillRect(0,0,canvasW,canvasH),context.font="bold "+fontSize+"px monaco, consolas, courier, monospace";var a,_;for(a=0;mapW>=a;++a)if(matrixMap[a][mActive])for(_=0;mapH>=_;++_)0!=matrixMap[a][_][mType]&&(context.fillStyle="rgb("+matrixMap[a][_][mWhite]+", "+Math.max(matrixMap[a][_][mGreen],matrixMap[a][_][mWhite])+", "+matrixMap[a][_][mWhite]+")",matrixMap[a][_][mTextActive]&&" "!=matrixMap[a][_][mText]&&0!=matrixMap[a][_][mText].length||context.fillText(matrixMap[a][_][mSymbol],a*fontSize,_*fontSize));for(a=textX;a!=charText[0].length+textX;++a)for(_=textY;_!=charText.length+textY;++_)matrixMap[a][_][mTextActive]&&" "!=matrixMap[a][_][mText]&&matrixMap[a][_][mText].length>0&&(context.fillStyle="rgb(249, 0, 0)",context.fillText(matrixMap[a][_][mText],a*fontSize,_*fontSize))}function launch(){clearInterval(timer);var a=currentTime.getMilliseconds();update(),draw(),timer=setInterval(launch,refreshDelay-(currentTime.getMilliseconds()-a))}function init(){clearInterval(timer),currentTime=new Date,fontSize=14+Math.max(parseInt((document.body.offsetWidth-1200)/100),0),minWidth=charText[0].length*fontSize,minHeight=charText.length*fontSize,windowWidth=Math.max(document.body.offsetWidth,minWidth),windowHeight=Math.max(document.body.offsetHeight-5,minHeight),document.body.style.minWidth=minWidth,document.body.style.minHeight=minHeight,canvas=document.getElementById("mainCanvas"),canvas.width=parseInt(windowWidth/fontSize)*fontSize,canvas.height=parseInt(windowHeight/fontSize)*fontSize,canvasW=canvas.width,canvasH=canvas.height,context=canvas.getContext("2d"),mapW=parseInt(canvasW/fontSize),mapH=parseInt(canvasH/fontSize),maxPause=1,maxDropRdmArg=1,maxDropsINColumn=2,refreshDelay=25,completedFromLeft=0,timer=setInterval(launch,refreshDelay),canvas.style.margin=0,canvas.style.marginLeft=parseInt((windowWidth-canvasW)/2)+"px",canvas.style.marginTop=parseInt((windowHeight-canvasH)/2)+"px",canvas.style.marginLeft%2!=0&&canvas.style.marginLeft--,canvas.style.marginLeft+="px",textX=parseInt((mapW-charText[0].length)/2),textY=parseInt((mapH-charText.length)/2),matrixMap[mColumnUsedCount]=0;for(var a=0;mapW>=a;++a){matrixMap[a]=[],matrixMap[a][mDropsCount]=0,matrixMap[a][mColumnUsed]=!1,matrixMap[a][mActive]=!1;for(var _=0;mapH>=_;++_)matrixMap[a][_]=[],matrixMap[a][_][mType]=0,matrixMap[a][_][mPauseValue]=0,matrixMap[a][_][mCurrentPause]=0,matrixMap[a][_][mGreen]=0,matrixMap[a][_][mWhite]=0,matrixMap[a][_][mSymbol]="",matrixMap[a][_][mFade]=0,matrixMap[a][_][mText]="",matrixMap[a][_][mTextActive]=!1}for(var a=0,t=textX;a!=charText[0].length;++a,++t)for(var _=0,e=textY;_!=charText.length;++_,++e)matrixMap[t][e][mText]=charText[_][a]}var letters="アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユ42ヨラリルレロワヰヱヲンㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄒㄓㄔㄕㄗㄘㄙㄚㄛㄜㄝㄞㄠㄡㄢㄣㄤㄥㄦㄨㄩㄪㄫㄬ",chrSetPow=letters.length,fontSize,textX,textY,currentTime,context,timer,mapW,mapH,maxPause,maxDropRdmArg,maxDropsINColumn,refreshDelay,matrixMap=[],completedFromLeft,minWidth,minHeight,windowWidth,windowHeight,canvas,charText=["","","","",""],mDropsCount="mDropsCount",mActive="mActive",mType="mType",mPauseValue="mPauseValue",mCurrentPause="mCurrentPause",mGreen="mGreen",mWhite="mWhite",mSymbol="mSymbol",mText="mText",mTextActive="mTextActive",mColumnUsed="mColumnUsed",mColumnUsedCount="mColumnUsedCount",mFade="mFade";