Jony/assets/backdrop/backdrop1.js

1 line
1.8 KiB
JavaScript
Raw Normal View History

2021-01-25 04:59:40 +00:00
!function(){function e(){let e=document.getElementsByTagName("script"),t=e.length,n=e[t-1];return{length:t,z:-510,opacity:n.getAttribute("opacity")||.5,color:n.getAttribute("color")||"0,0,0",count:n.getAttribute("count")||99}}function t(){W=i.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,H=i.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}function n(){o.clearRect(0,0,W,H);var e,t,i=[x].concat(d);d.forEach(function(n){n.x+=n.xa,n.y+=n.ya,n.xa=n.xa*(n.x>W||n.x<0?-1:1),n.ya=n.ya*(n.y>H||n.y<0?-1:1),o.fillRect(n.x-.5,n.y-.5,1,1);for(let c=0;c<i.length;c++)e=i[c],n!==e&&null!==e.x&&null!==e.y&&(x_diff=n.x-e.x,y_diff=n.y-e.y,distance=x_diff*x_diff+y_diff*y_diff,distance<e.max&&(e===x&&distance>e.max/2&&(n.x=n.x-.03*x_diff,n.y=n.y-.03*y_diff),t=(e.max-distance)/e.max,o.beginPath(),o.lineWidth=t/2,o.strokeStyle="rgba("+a.color+","+(t+.2)+")",o.moveTo(n.x,n.y),o.lineTo(e.x,e.y),o.stroke()));i.splice(i.indexOf(n),1)}),y(n)}var i=document.createElement("canvas"),o=i.getContext("2d"),a=e();i.id="c_n"+a.length,i.style.cssText="position:fixed;top:0;left:0;pointer-events:none;z-index:"+a.z+";opacity:"+a.opacity,document.getElementsByTagName("body")[0].appendChild(i),t(),window.onresize=t;var c=Math.random,d=[];for(let e=0;e<a.count;e++){var l=c()*W,u=c()*H,m=2*c()-1,r=2*c()-1;d.push({x:l,y:u,xa:m,ya:r,max:6e3})}var x={x:null,y:null,max:2e4};window.onmousemove=function(e){e=e||window.event,x.x=e.clientX,x.y=e.clientY},window.onmouseout=function(){x.x=null,x.y=null};var y=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1e3/45)};setTimeout(function(){n()},100)}();