-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsnowflake.min.js
11 lines (11 loc) · 3.42 KB
/
snowflake.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
Source: https://github.com/nextapps-de/snowflake
License: Apache License 2.0
*/
(function(){'use strict';function C(a){var c=Math.random()*z.length|0;let d=z[c];var b;if(!(b=t[c])){b=z[c];c=t[c]=document.createElement("canvas");const g=c.getContext("2d"),q=Math.ceil(b.r*h*f*n),I=b.r<2.3?(2.3-b.r)*.9*h*f:b.r>2.3?(b.r-2.3)*1.1*h*f:0;c.height=c.width=q;g.globalAlpha=b.g;g.filter=g.webkitFilter="blur("+I+"px)";g.drawImage(e,0,0,e.width,e.height,0,0,q,q);g.globalAlpha=b.g/1.5;g.fillStyle="#e4ecf4";g.beginPath();g.arc(q/2,q/2,q/2/2,0,Math.PI*2,!1);g.closePath();g.fill();b=c}this.buffer=
b;this.r=d.r*h*f;this.w=Math.ceil(d.r*h*f*n);this.x=Math.random()*(k||1);this.y=a||-this.w;this.g=d.g;this.j=d.r*d.r*h*f/n/2;this.i=(.5-Math.random()*1)/n*h*f;this.h=(1-Math.random()*2)*n/h/f/180*Math.PI}function A(a){v=window.requestAnimationFrame(A);if(e.loaded){D.clearRect(0,0,k,l);var c=w?(a-w)/(1E3/60):1;c>100&&(c=1);w=a;for(let d=0,b,g=E*F|0;d<g;d++)b=r[d]||(r[d]=new C(Math.random()*(l||1))),b.y+=b.j*c*x*(n/3),b.x+=b.i*c*x+Math.sin(b.y/x/(n/3)*b.h)/2*h*f,b.y>=l||b.x>=k||b.x<=-b.w?r.length>g?
r.splice(d--,1):r[d]=new C(0):D.drawImage(b.buffer,0,0,b.w,b.w,b.x,b.y,b.w,b.w)}}function y(){let a=m.parentElement;!a||a===document.body&&(a=document.documentElement);a?(k=a.clientWidth,l=a.clientHeight):(k=window.innerWidth,l=window.innerHeight);k=k/3*h*f;l=l/3*h*f;E=k/(h*f)*(l/(h*f))/1500|0;m.width=k;m.height=l}function p(a){const c=m.style;for(const d in a)c.setProperty(d,a[d])}function B(){const a=window.SnowflakeConfig;if(a)for(let c in a)c==="start"?u=!!a[c]:J[c](a[c]);e.loaded||e.src||(e.src=
G);u&&H()}function H(){y();A(0);u=!0;m.setAttribute("id","snowflake");m.parentElement||document.body.appendChild(m)}const m=document.createElement("canvas"),D=m.getContext("2d"),h=window.devicePixelRatio||1,e=new Image,G="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAGFBMVEXk7PTk7PTk7PTk7PTk7PTk7PQAAADk7PQLtLMUAAAAB3RSTlO18FHbI4YAkU+M0QAAAVVJREFUeF7F1T1PwzAQgGGGouwg5B8QEWaioqyVSsNKoXL2KPYcE6L371PLcp1GjU7A0IztI53Pvo8bK3y/BnkpgGoQAFwXmPvCg/ZZL4A3hg94rPheBOFbBCaCiyHqo9gpAHc44m4Ots6L9h1uC/+/Ws/AE3qapuFrBpo5GCdgX14G+UMAHaxsRjEFLb3dQB0BB0U9BR1uRwS2Acdw/hYVCkYbQJcB4zlogL6OWbQV9OchMhiKlKYBxinYA9omsAW4SyAHWCfQKgagjGADVLgUogGdA6sAdh4bGCMw0PuwOO2BCQlmoBPQ8eAQUzIJdKo8JQunBHN3uodXa8NZAfCRbPg5glnN6eW+2BBy+RtIIQ4JSIcU0xQvSrxq6bHE5xYLRi45uWjlspcbR249uXnl9pcHiDyC0hD7hJc0xMQxKA9SeRTLw1xeB9ffWfJilVfz/7f/D7vzJWHzmXRTAAAAAElFTkSuQmCC";
let k,l,E,v=0,w=0,x=1,n=3,F=1,f=1.5,u=!0;const r=[],t=[],z=[{r:1.5,g:.3},{r:1.7,g:.4},{r:1.9,g:.6},{r:2.1,g:.8},{r:2.3,g:1},{r:2.5,g:1},{r:2.7,g:.8},{r:2.9,g:.6},{r:3.1,g:.4},{r:3.5,g:.3}];window.addEventListener("resize",y,!1);const J=window.Snowflake={style:p,speed:function(a){x=a},size:function(a){n=3*a;t.length=0},quality:function(a){f=1.5*Math.min(Math.max(a,.1),2);t.length=0;r.length=0;y()},density:function(a){F=a},opacity:function(a){p({opacity:a})},index:function(a){p({"z-index":a})},image:function(a){e.loaded=
!a;a&&(e.src=a);t.length=0},mount:function(a){a.appendChild(m);p({position:a===document.body?"fixed":"absolute"});u&&y()},start:function(){u?v||A(0):B()||H();p({display:""})},stop:function(){cancelAnimationFrame(v);p({display:"none"});v=w=0}};p({position:"fixed",top:"0",left:"0",width:"100%",height:"100%","z-index":"999999","pointer-events":"none"});e.loaded=!1;e.onload=function(){e.loaded=!0};e.onerror=function(){e.onerror=null;e.src=G};document.readyState==="complete"?B():window.addEventListener("load",
B,!1)})();