2023-03-21 13:54:36 +08:00

1 line
5.7 KiB
JavaScript

$(function(){var n,i,o,r,t=function(){"use strict";function L(t){return"function"==typeof t}function R(t){return"string"==typeof t}function _(t,e,n){for(var i in e)!n&&t.hasOwnProperty(i)||(t[i]=e[i]);return t}function W(t){var e,n={};for(e in t)n[e]=L(t[e])?function(t,e){return function(){t.apply(e,arguments)}}(t[e],t):t[e];return n}function n(o){function n(t){L(t)&&t.apply(o,[].splice.call(arguments,1))}function t(t){for(f=0;f<k.length;f++)R(m=k[f])?l[(t?"add":"remove")+"EventListener"].call(l,m,u,!1):L(m)?u=m:l=m}function e(){l=N?o.style:o.canvas,p=N?"px":"",o.fullscreen&&(o.height=G.innerHeight,o.width=G.innerWidth),l.height=o.height+p,l.width=o.width+p,o.retina&&A&&I&&(l.height=o.height*I,l.width=o.width*I,l.style.height=o.height+"px",l.style.width=o.width+"px",o.scale(I,I)),T&&n(o.resize)}function i(t,e){return n=t,i=o.element,d=i.getBoundingClientRect(),n.x=n.pageX-d.left-G.scrollX,n.y=n.pageY-d.top-G.scrollY,(e=e||{}).ox=e.x||t.x,e.oy=e.y||t.y,e.x=t.x,e.y=t.y,e.dx=e.x-e.ox,e.dy=e.y-e.oy,e;var n,i}function r(t){for(t=function(t){if(t.preventDefault(),(y=W(t)).originalEvent=t,y.touches)for(P.length=y.touches.length,f=0;f<y.touches.length;f++)P[f]=i(y.touches[f],P[f]);else P.length=0,P[0]=i(y,O);return _(O,P[0],!0),y}(t),E=(b=k.indexOf(v=t.type))-1,o.dragging=!!/down|start/.test(v)||!/up|end/.test(v)&&o.dragging;E;)R(k[E])?n(o[k[E--]],t):R(k[b])?n(o[k[b++]],t):E=0}function a(){o.now=+new Date,o.running=!0}function s(){o.running=!1}var c,u,l,h,d,f,p,g,m,y,v,w,x,E,b,C=0,P=[],T=!1,I=G.devicePixelRatio,N=o.type==D,A=o.type==B,O={x:0,y:0,ox:0,oy:0,dx:0,dy:0},k=[o.element,r,"mousedown","touchstart",r,"mousemove","touchmove",r,"mouseup","touchend",r,"click",F,function(t){var e;w=t.keyCode,x="keyup"==t.type,S[w]=S[H[e=w]||String.fromCharCode(e)]=!x,n(o[t.type],t)},"keydown","keyup",G,function(t){o.autopause&&("blur"==t.type?s:a)(),n(o[t.type],t)},"focus","blur",e,"resize"],S={};for(w in H)S[H[w]]=!1;return _(o,{touches:P,mouse:O,keys:S,dragging:!1,running:!1,millis:0,now:NaN,dt:NaN,destroy:function(){h=o.element.parentNode,f=z.indexOf(o),h&&h.removeChild(o.element),~f&&z.splice(f,1),t(!1),s()},toggle:function(){(o.running?s:a)()},clear:function(){A&&o.clearRect(0,0,o.width,o.height)},start:a,stop:s}),z.push(o),o.autostart&&a(),t(!0),e(),function t(){q(c),c=X(t),T||(n(o.setup),T=L(o.setup),n(o.resize)),o.running&&!C&&(o.dt=(g=+new Date)-o.now,o.millis+=o.dt,o.now=g,n(o.update),o.autoclear&&A&&o.clear(),n(o.draw)),C=++C%o.interval}(),o}var t=document.createElement("div");t.setAttribute("id","clickCanvas"),t.style.cssText="position:fixed;left:0;top:0;z-index:1000;pointer-events:none;",document.body.appendChild(t);for(var e,i,o="E LN10 LN2 LOG2E LOG10E PI SQRT1_2 SQRT2 abs acos asin atan ceil cos exp floor log round sin sqrt tan atan2 pow max min".split(" "),r="__hasSketch",a=Math,B="canvas",s="webgl",D="dom",F=document,G=window,z=[],c={fullscreen:!0,autostart:!0,autoclear:!0,autopause:!0,container:F.body,interval:1,globals:!0,retina:!1,type:B},H={8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",27:"ESCAPE",32:"SPACE",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN"},u={CANVAS:B,WEB_GL:s,WEBGL:s,DOM:D,instances:z,install:function(t){if(!t[r]){for(var e=0;e<o.length;e++)t[o[e]]=a[o[e]];_(t,{TWO_PI:2*a.PI,HALF_PI:a.PI/2,QUATER_PI:a.PI/4,random:function(t,e){return n=t,"[object Array]"===Object.prototype.toString.call(n)?t[~~(a.random()*t.length)]:("number"!=typeof e&&(e=t||1,t=0),t+a.random()*(e-t));var n},lerp:function(t,e,n){return t+n*(e-t)},map:function(t,e,n,i,o){return(t-e)/(n-e)*(o-i)+i}}),t[r]=!0}},create:function(t){return(t=_(t||{},c)).globals&&u.install(self),e=t.element=t.element||F.createElement(t.type===D?"div":"canvas"),i=t.context=t.context||function(){switch(t.type){case B:return e.getContext("2d",t);case s:return e.getContext("webgl",t)||e.getContext("experimental-webgl",t);case D:return e.canvas=e}}(),t.container.appendChild(e),u.augment(i,t)},augment:function(t,e){return(e=_(e||{},c)).element=t.canvas||t,e.element.className+=" sketch",_(t,e,!0),n(t)}},l=["ms","moz","webkit","o"],h=self,d=0,f="AnimationFrame",p="request"+f,t="cancel"+f,X=h[p],q=h[t],g=0;g<l.length&&!X;g++)X=h[l[g]+"Request"+f],q=h[l[g]+"Cancel"+p];return h[p]=X=X||function(t){var e=+new Date,n=a.max(0,16-(e-d)),i=setTimeout(function(){t(e+n)},n);return d=e+n,i},h[t]=q=q||function(t){clearTimeout(t)},u}();function a(t,e,n){this.init(t,e,n)}document.getElementById("clickCanvas")&&(a.prototype={init:function(t,e,n){this.alive=!0,this.radius=n||10,this.wander=.15,this.theta=random(TWO_PI),this.drag=.92,this.color="#ffeb3b",this.x=t||0,this.y=e||0,this.vx=0,this.vy=0},move:function(){this.x+=this.vx,this.y+=this.vy,this.vx*=this.drag,this.vy*=this.drag,this.theta+=random(-.5,.5)*this.wander,this.vx+=.1*sin(this.theta),this.vy+=.1*cos(this.theta),this.radius*=.96,this.alive=.5<this.radius},draw:function(t){t.beginPath(),t.arc(this.x,this.y,this.radius,0,TWO_PI),t.fillStyle=this.color,t.fill()}},n=["#5ee4ff","#f44033","#ffeb3b","#F38630","#FA6900","#f403e8","#F9D423"],i=[],o=[],(r=t.create({container:document.getElementById("clickCanvas")})).spawn=function(t,e){50<=i.length&&o.push(i.shift()),(particle=o.length?o.pop():new a).init(t,e,random(5,20)),particle.wander=random(.5,2),particle.color=random(n),particle.drag=random(.9,.99),theta=random(TWO_PI),force=random(1,5),particle.vx=sin(theta)*force,particle.vy=cos(theta)*force,i.push(particle)},r.update=function(){for(var t,e=i.length-1;0<=e;e--)(t=i[e]).alive?t.move():o.push(i.splice(e,1)[0])},r.draw=function(){r.globalCompositeOperation="lighter";for(var t=i.length-1;0<=t;t--)i[t].draw(r)},document.addEventListener("mousedown",function(t){var e,n;if("TEXTAREA"!==t.target.nodeName&&"INPUT"!==t.target.nodeName&&"A"!==t.target.nodeName&&"I"!==t.target.nodeName&&"IMG"!==t.target.nodeName)for(e=random(15,20),n=0;n<e;n++)r.spawn(t.clientX,t.clientY)}))});