-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangleBanner.min.js
More file actions
7 lines (7 loc) · 10.8 KB
/
TriangleBanner.min.js
File metadata and controls
7 lines (7 loc) · 10.8 KB
1
2
3
4
5
6
7
/***************
Copyright 2017 Mitchell Woodhouse Mckenzie
Created By: Mitchell Woodhouse Mckenzie
Website: www.woodhousemckenzie.com
Date: 04/27/2017
***************/
function Random(a,b){return Math.floor(Math.random()*(b-a)+a)}function Node(a,b,c){this.x=a,this.y=b,this.color=c,this.anim=0,this.anim2=0,this.animCount=0,this.animCount2=0,this.animating=!1,this.alpha=1}function TriangleBanner(a){var b,c,d,e,g,h,i,j,l,n,v,w,x,C,R,S,T,U,V,W,X,f=[],k=0,m=0,o=[],p=!1,q=0,r=0,s=0,t=0,u=1,y=.15,z=0,A=!1,B=null,D=-1,E=!1,F=0,G=[],H=function(a){for(var b=[],c=a.split("-"),d=0;d<c.length;d++)switch(c[d]){case"blue":b.push("#0a3f6f","#0b477d","#0D4F8B","#3d72a2","#256096");break;case"red":b.push("#cc1e1e","#e52222","#ff2626","#ff3b3b","#ff5151");break;case"purple":b.push("#240643","#29074b","#2E0854","#422065","#573976");break;case"green":b.push("#3c8c40","#449d48","#4CAF50","#5db761","#6fbf72");break;case"yellow":b.push("#ccab00","#e5c000","#FFD600","#ffde32","#ffe666");break;case"orange":b.push("#cc451b","#e54e1e","#FF5722","#ff6738","#ff784e");break;case"brown":b.push("#604439","#6c4c40","#795548","#86665a","#93766c");break;case"pink":b.push("#c40045","#dc004e","#F50057","#f61967","#f73278");break;case"gray":b.push("#7e7e7e","#8e8e8e","#9E9E9E","#a7a7a7","#b1b1b1");break;case"white":b.push("#bebebe","#d6d6d6","#EEEEEE","#f6f6f6","#ffffff")}return b},I=function(){if(null!=b.getAttribute("outlineStyle"))switch(b.getAttribute("outlineStyle")){case"1":c.lineWidth=1;break;case"2":c.lineWidth=.1;break;case"3":c.lineWidth=10;break;case"4":c.lineWidth=100;break;default:c.lineWidth=1}else c.lineWidth=1;if(null!=b.getAttribute("triangleHeight")){var a=parseInt(b.getAttribute("triangleHeight"));isNaN(a)?(i=e/6,j=e/6+e/8):(i=e/a,j=e/a+e/(a+2))}else i=e/6,j=e/6+e/8;if(null!=b.getAttribute("triangleWidth")){var a=parseInt(b.getAttribute("triangleWidth"));isNaN(a)?(g=d/10,h=d/10):(g=d/a,h=d/a)}else g=d/10,h=d/10;if(G=H(null!=b.getAttribute("color")?b.getAttribute("color"):"blue"),0==G.length&&(G=H("blue")),null!=b.getAttribute("resize")){var f="true"==b.getAttribute("resize");A=f,A&&(document.getElementsByTagName("BODY")[0].onresize=function(){null!=B&&clearTimeout(B),B=setTimeout(function(){clearInterval(C),ea()},200)})}else A=!1;if(null!=b.getAttribute("alternate")){var k="true"==b.getAttribute("alternate");E=k}if(null!=b.getAttribute("animation")){var l=parseInt(b.getAttribute("animation"));isNaN(l)?(m=0,n=50):(m=l,1==l?n=50:2==l?n=1:3==l?n=1:4==l?(n=10,o=H("blue")):5==l?(n=2,o=H("blue")):6==l&&(n=2,o=H("blue")))}else m=0,n=50;if(o=H(null!=b.getAttribute("animationColors")?b.getAttribute("animationColors"):"blue"),0==o.length&&(o=H("blue")),null!=b.getAttribute("direction")){var p=parseInt(b.getAttribute("direction"));isNaN(p)||1==p&&(D=1)}if(null!=b.getAttribute("animationSpeed")){var q=parseInt(b.getAttribute("animationSpeed"));n=isNaN(q)?50:q}if(null!=b.getAttribute("animationDelay")){var r=parseInt(b.getAttribute("animationDelay"));isNaN(r)||(F=r)}},J=function(){for(var a=0;a<f.length;a+=2)for(var b=0;b<k;b++)a+1<f.length&&(c.globalAlpha=f[a][b].alpha,c.strokeStyle=f[a][b].color,c.fillStyle=f[a][b].color,c.beginPath(),c.moveTo(f[a][b].x,f[a][b].y),c.lineTo(f[a][b+1].x,f[a][b+1].y),c.lineTo(f[a+1][b].x,f[a+1][b].y),c.closePath(),c.fill(),c.stroke(),c.globalAlpha=1),0!=a&&(c.globalAlpha=f[a][b+1].alpha,c.strokeStyle=f[a][b+1].color,c.fillStyle=f[a][b+1].color,c.beginPath(),c.moveTo(f[a][b].x,f[a][b].y),c.lineTo(f[a][b+1].x,f[a][b+1].y),c.lineTo(f[a-1][b].x,f[a-1][b].y),c.closePath(),c.fill(),c.stroke(),c.globalAlpha=1);for(var a=1;a<f.length;a+=2)for(var b=0;b<k-1;b++)c.globalAlpha=f[a][b].alpha,c.strokeStyle=f[a][b].color,c.fillStyle=f[a][b].color,c.beginPath(),c.moveTo(f[a][b].x,f[a][b].y),c.lineTo(f[a][b+1].x,f[a][b+1].y),c.lineTo(f[a-1][b+1].x,f[a-1][b+1].y),c.closePath(),c.fill(),c.stroke(),c.globalAlpha=1,a+1<f.length&&(c.globalAlpha=f[a][b+1].alpha,c.strokeStyle=f[a][b+1].color,c.fillStyle=f[a][b+1].color,c.beginPath(),c.moveTo(f[a][b].x,f[a][b].y),c.lineTo(f[a][b+1].x,f[a][b+1].y),c.lineTo(f[a+1][b+1].x,f[a+1][b+1].y),c.closePath(),c.fill(),c.stroke(),c.globalAlpha=1)},K=!1,L=!1,M=0,N=0,O=!1,P=function(){if(p||(s=Random(-50,50),t=Random(-50,50),M+=s,N+=t,p=!0),Math.round(10*q)/10==s&&(K=!0,0==F&&(K=!1,s=Random(-75,75),M>0?M+s>50?s=-1*M:M+=s:M+s<-50?s=-1*M:M+=s)),Math.round(10*r)/10==t&&(L=!0,0==F&&(L=!1,t=Random(-75,75),N>0?N+t>50?t=-1*N:N+=t:N+t<-50?t=-1*N:N+=t)),K&&L&&!O&&0!=F&&(O=!0,L=!1,K=!1,setTimeout(function(){s=Random(-50,50),t=Random(-50,50),M>0?M+s>50?s=-1*M:M+=s:M+s<-50?s=-1*M:M+=s,N>0?N+t>50?t=-1*N:N+=t:N+t<-50?t=-1*N:N+=t,O=!1},F)),!O){K||(q>s?q-=.5:q+=.5),L||(r>t?r-=.5:r+=.5);for(var a=0;a<f.length;a++)for(var b=0;b<f[a].length;b++)K||(q>s?f[a][b].x-=.5:f[a][b].x+=.5),L||(r>t?f[a][b].y-=.5:f[a][b].y+=.5);ba()}},Q=!1,Y=function(){if(!O){u>=l&&(O=!0,setTimeout(function(){E&&(D*=-1,Q=!1),v=1==D?d+3*h:-1.5*h,u=1,O=!1},F)),Q||(1==D?(S=-1,R=f.length-1,T=-1,X=-1):(R=0,S=f.length,T=1,X=1),Q=!0);for(var a=R;a!=S;a+=T){1==D?(V=-1,U=f[a].length-1,W=-1):(U=0,V=f[a].length,W=1);for(var b=U;b!=V;b+=W)f[a][b].animating?0==f[a][b].anim?Math.round(10*f[a][b].animCount)/10<x?f[a][b].anim=1:(f[a][b].y-=y,f[a][b].animCount-=y):1==f[a][b].anim?Math.round(10*f[a][b].animCount)/10>0?f[a][b].anim=2:(f[a][b].y+=y,f[a][b].animCount+=y):(f[a][b].animating=!1,f[a][b].animCount=0,f[a][b].anim=0,u+=1):Math.floor(f[a][b].x)==Math.floor(v)&&(f[a][b].animating=!0)}v+=X,ba()}},Z=function(){if(!O){u>=l&&(O=!0,setTimeout(function(){E&&(D*=-1,Q=!1),v=1==D?d+3*h:-1.5*h,z=0==z?1:0,u=1,O=!1},F)),Q||(1==D?(S=-1,R=f.length-1,T=-1,X=-1):(R=0,S=f.length,T=1,X=1),Q=!0);for(var a=R;a!=S;a+=T){1==D?(V=-1,U=f[a].length-1,W=-1):(U=0,V=f[a].length,W=1);for(var b=U;b!=V;b+=W)f[a][b].animating?0==f[a][b].anim?Math.round(10*f[a][b].animCount)/10<x?f[a][b].anim=1:(f[a][b].y-=y,f[a][b].animCount-=y):1==f[a][b].anim||2==f[a][b].anim?Math.round(10*f[a][b].animCount)/10>0?f[a][b].anim=3:(f[a][b].y+=y,f[a][b].animCount+=y):(f[a][b].color=0==z?o[Random(0,o.length)]:G[Random(0,G.length)],f[a][b].animating=!1,f[a][b].animCount=0,f[a][b].anim=0,u+=1):Math.round(f[a][b].x)==Math.round(v)&&(f[a][b].animating=!0)}v+=X,ba()}},$=function(){if(!O){u>=l&&(O=!0,setTimeout(function(){E&&(D*=-1,Q=!1),v=1==D?d+3*h:-1.5*h,z=0==z?1:0,u=1,O=!1},F)),Q||(1==D?(S=-1,R=f.length-1,T=-1,X=-1):(R=0,S=f.length,T=1,X=1),Q=!0);for(var a=R;a!=S;a+=T){1==D?(V=-1,U=f[a].length-1,W=-1):(U=0,V=f[a].length,W=1);for(var b=U;b!=V;b+=W)f[a][b].animating?0==f[a][b].anim?(f[a][b].alpha-=.0125,f[a][b].animCount+=1,f[a][b].animCount>=80&&(f[a][b].anim=1,f[a][b].alpha=0,f[a][b].animCount=0)):1==f[a][b].anim||2==f[a][b].anim?(1==f[a][b].anim&&(f[a][b].anim=2,f[a][b].color=0==z?o[Random(0,o.length)]:G[Random(0,G.length)]),f[a][b].alpha+=.0125,f[a][b].animCount+=1,f[a][b].animCount>=80&&(f[a][b].anim=3,f[a][b].alpha=1,f[a][b].animCount=0)):(f[a][b].animating=!1,u+=1):Math.round(f[a][b].x)==Math.round(v)&&(f[a][b].alpha=1,f[a][b].anim=0,f[a][b].animating=!0,f[a][b].animCount=0)}v+=X,ba()}},_=function(){if(!O){u>=l&&(O=!0,setTimeout(function(){E&&(D*=-1,Q=!1),v=1==D?d+3*h:-1.5*h,z=0==z?1:0,u=1,O=!1},F)),Q||(1==D?(S=-1,R=f.length-1,T=-1,X=-1):(R=0,S=f.length,T=1,X=1),Q=!0);for(var a=R;a!=S;a+=T){1==D?(V=-1,U=f[a].length-1,W=-1):(U=0,V=f[a].length,W=1);for(var b=U;b!=V;b+=W)f[a][b].animating?(0==f[a][b].anim?Math.round(10*f[a][b].animCount)/10<x?f[a][b].anim=1:(f[a][b].y-=y,f[a][b].animCount-=y):1==f[a][b].anim||2==f[a][b].anim?Math.round(10*f[a][b].animCount)/10>0?f[a][b].anim=3:(f[a][b].y+=y,f[a][b].animCount+=y,f[a][b].animCount2<=80&&0!=f[a][b].alpha&&0==f[a][b].anim2?(f[a][b].alpha<=0&&(f[a][b].alpha=0),f[a][b].alpha-=.0125,f[a][b].animCount2+=1):0==f[a][b].anim2&&(f[a][b].color=0==z?o[Random(0,o.length)]:G[Random(0,G.length)],f[a][b].alpha=0,f[a][b].animCount2=0,f[a][b].anim2=1)):(f[a][b].animating=!1,f[a][b].animCount=0,f[a][b].anim=0,f[a][b].anim2=0,u+=1),1==f[a][b].anim2&&(f[a][b].alpha+=.0125,f[a][b].animCount2+=1,(f[a][b].alpha>=1||f[a][b].animCount2<=80)&&(f[a][b].alpha=1,f[a][b].animCount2=0,f[a][b].anim2=2))):Math.round(f[a][b].x)==Math.round(v)&&(f[a][b].animating=!0,f[a][b].alpha=1,f[a][b].animCount2=0,f[a][b].anim2=0)}v+=X,ba()}},aa=function(){if(!O){u>=l&&(O=!0,setTimeout(function(){E&&(D*=-1,Q=!1),v=1==D?d+3*h:-1.5*h,z=0==z?1:0,u=1,O=!1},F)),Q||(1==D?(S=-1,R=f.length-1,T=-1,X=-1):(R=0,S=f.length,T=1,X=1),Q=!0);for(var a=R;a!=S;a+=T){1==D?(V=-1,U=f[a].length-1,W=-1):(U=0,V=f[a].length,W=1);for(var b=U;b!=V;b+=W)f[a][b].animating?0==f[a][b].anim?Math.round(10*f[a][b].animCount)/10<x?f[a][b].anim=1:(f[a][b].y-=y,f[a][b].animCount-=y):1==f[a][b].anim||2==f[a][b].anim?(1==f[a][b].anim&&(f[a][b].color=0==z?o[Random(0,o.length)]:G[Random(0,G.length)],f[a][b].anim=2),Math.round(10*f[a][b].animCount)/10>0?f[a][b].anim=3:(f[a][b].y+=y,f[a][b].animCount+=y)):(f[a][b].animating=!1,f[a][b].animCount=0,f[a][b].anim=0,u+=1):Math.round(f[a][b].x)==Math.round(v)&&(f[a][b].animating=!0,f[a][b].anim=0)}v+=X,ba()}},ba=function(){c.clearRect(0,0,b.width,b.height),J()},ca=function(){var a=-1*h,b=-2*h,c=0,o=!0,p=0,q=e/8;for(f[c]=[],f[c].push([a,b-Random(-1*q,q)]);o;)if(a>d+h||c>0&&p>=k){c%2==0?(p+1==k&&f[c].push(new Node(f[0][k-1][0],f[0][k-1][1],G[Random(0,G.length)])),a=-1*h):a=-1.5*h,p=0;var r=Random(i,j);b+=r,b>e+2*j?o=!1:(c+=1,f.push([]),f[c].push(new Node(a,b-Random(-1*q,q),G[Random(0,G.length)])))}else 0==c&&(k+=1),p+=1,c%2!=0&&p>=k?a=d+h/2:(a+=Random(g,h),f[c].push(new Node(a,b-Random(-1*q,q),G[Random(0,G.length)])));J(),l=0;for(var s=0;s<f.length;s++)l+=f[s].length;v=1==D?d+3*h:-1.5*h,w=!0,x=e/6*-1,minPeak=e/18,m>0&&m<7&&(C=setInterval(function(){1==m?P():2==m?Y():3==m?Z():4==m?$():5==m?_():6==m&&aa()},n))},ea=function(){if(b=document.getElementById(a),null!=b.getAttribute("quality")){switch(b.getAttribute("quality")){case"low":e=b.parentNode.scrollHeight/4,d=b.parentNode.scrollWidth/4;break;case"med":e=b.parentNode.scrollHeight/2,d=b.parentNode.scrollWidth/2;break;case"high":e=b.parentNode.scrollHeight,d=b.parentNode.scrollWidth;break;case"ultra":e=2*b.parentNode.scrollHeight,d=2*b.parentNode.scrollWidth;break;default:e=b.parentNode.scrollHeight,d=b.parentNode.scrollWidth}}else e=b.parentNode.scrollHeight,d=b.parentNode.scrollWidth;b.style.width=b.parentNode.scrollWidth+"px",b.style.height=b.parentNode.scrollHeight+"px",b.width=d,b.height=e,f=[],k=0,z=0,Q=!1,ca()};!function(){if(b=document.getElementById(a),c=b.getContext("2d"),null!=b.getAttribute("quality")){switch(b.getAttribute("quality")){case"low":e=b.parentNode.scrollHeight/4,d=b.parentNode.scrollWidth/4;break;case"med":e=b.parentNode.scrollHeight/2,d=b.parentNode.scrollWidth/2;break;case"high":e=b.parentNode.scrollHeight,d=b.parentNode.scrollWidth;break;case"ultra":e=2*b.parentNode.scrollHeight,d=2*b.parentNode.scrollWidth;break;default:e=b.parentNode.scrollHeight,d=b.parentNode.scrollWidth}}else e=b.parentNode.scrollHeight,d=b.parentNode.scrollWidth;b.style.width=b.parentNode.scrollWidth+"px",b.style.height=b.parentNode.scrollHeight+"px",b.width=d,b.height=e,I(),ca()}()}