Jony/assets/backdrop/backdrop1.js

1 line
1.7 KiB
JavaScript
Raw Normal View History

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