@mattereum/voltsig
Version:
High-entropy human-readable hashes
2 lines (1 loc) • 5.8 kB
JavaScript
const voltsig=function(){const o=[{r:192,g:64,b:64},{r:192,g:128,b:64},{r:176,g:192,b:64},{r:96,g:192,b:64},{r:64,g:192,b:192},{r:64,g:128,b:192},{r:80,g:64,b:192},{r:192,g:64,b:192}],t=[{rotation:0,reflection:-1},{rotation:90,reflection:1}],r=[0,30,60,90,120,150,180,210,240,270,300,330],n=["M -4,-6 L -4,6","M -4,-6 L -4,6 M 4,4 L 4,6 L 1,6 L 1,4 Z","M -4,-6 L -4,6 M 4,5 C 4,6.1 3.1,7 2,7 C 0.9,7 0,6.1 0,5 C 0,3.9 0.9,3 2,3 C 3.1,3 4,3.9 4,5 Z","M -4,-6 L -4,4 L -2,4","M -4,-6 L -4,2 M 4,4 L 0,7","M -4,-6 L -4,3 C -4,5.2 -2.2,7 0,7 C 2.2,7 4,5.2 4,3","M -4,-6 L -4,6 L 0,6","M -4,-6 L -4,6 M -4,1 L 4,6","M -4,-6 L -4,0 C -4,4 2,2 2,6 L -2,6"],e=["M -4,-6 L 4,-6","M -4,-6 L 2,-6 C 3.1,-6 4,-5.1, 4,-4 M -7,0 L 0,0","M -4,0 L 4,0 L 4,-2","M -4,-6 L 0,-6 M -4,0 L 4,0","M -4,-6 L 1,-6 C 2.7 -6 4 -4.7 4 -3 C 4 -1.3 2.7 0 1 0 L -6 0","M -4,-6 L -4,-4 C -4,-1.8 -2.2,0 0,0 C 2.2,0 4,-1.8 4,-4","M 4,-6 C 4,-2.6 1.4,0 -2,0 L -6,0","M 4,-6 L 4,0"],f=[[{x:0,y:0},{x:1,y:0},{x:1,y:1}],[{x:1,y:0},{x:1,y:1},{x:0,y:1}],[{x:1,y:1},{x:0,y:1},{x:0,y:0}],[{x:0,y:1},{x:0,y:0},{x:1,y:0}],[{x:0,y:1},{x:1,y:1},{x:1,y:2}],[{x:1,y:1},{x:1,y:2},{x:0,y:2}],[{x:1,y:2},{x:0,y:2},{x:0,y:1}],[{x:0,y:2},{x:0,y:1},{x:1,y:1}]],l=[[{from:-4,to:4}],[{from:-1,to:4}],[{from:-1,to:1}],[{from:-1,to:1},{from:2,to:4}],[{from:-4,to:1}],[{from:-4,to:-2},{from:2,to:4}],[{from:-4,to:-2},{from:-1,to:1}],[{from:-4,to:-2},{from:-1,to:1},{from:2,to:4}]],i=[{a:[{from:"0",to:"++"}],b:[{from:"0",to:"++"}]},{a:[{from:"--",to:"0"},{from:"+",to:"++"}],b:[{from:"--",to:"0"},{from:"+",to:"++"}]},{a:[{from:"-",to:"++"}],b:[{from:"+",to:"++"}]},{a:[{from:"+",to:"++"}],b:[{from:"-",to:"++"}]},{a:[{from:"--",to:"++"}],b:[{from:"+",to:"++"}]},{a:[{from:"+",to:"++"}],b:[{from:"--",to:"++"}]},{a:[{from:"--",to:"++"}],b:[{from:"--",to:"-"},{from:"+",to:"++"}]},{a:[{from:"--",to:"-"},{from:"+",to:"++"}],b:[{from:"--",to:"++"}]}];function c(o,t){return{x:o.x+t.x,y:o.y+t.y}}function x(o,t){return{x:o.x-t.x,y:o.y-t.y}}function s(o,t){return{x:o.x*t,y:o.y*t}}function a(o,t){return o.x*t.x+o.y*t.y}function m(o){return s(o,1/Math.sqrt(a(o,o)))}function y(o){return{x:-o.y,y:o.x}}function h(o){return`${o.x},${o.y}`}function g(o,t,r){const n=.2126*o.r+.7152*o.g+.0722*o.b,e=128+64*r;return`rgb(${Math.floor(e+t*(o.r-n))},${Math.floor(e+t*(o.g-n))},${Math.floor(e+t*(o.b-n))})`}function d(o,t){const r=document.createElementNS("http://www.w3.org/2000/svg",o);for(const[o,n]of Object.entries(t))r.setAttribute(o,n);return r}return function(u,M,L){const p=L.logoURL||"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgLTMgMjAgMjAiPgo8cGF0aCBmaWxsPSJ3aGl0ZSIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSIxIiBkPSJNIDEsMiBDIDIsMSA1LDEgNiwyIDgsMSAxMiwxIDE0LDIgMTUsMSAxOCwxIDE5LDIgMTgsNCAxNyw0IDE1LDUgMTQsOSAxMywxNCAxMCwxNCA3LDE0IDYsOSA1LDUgMyw0IDIsNCAxLDIgeiIvPgo8L3N2Zz4=";let C=u;const b=C.cloneNode(!1);C.parentElement.replaceChild(b,C),C=void 0;const I=String(M),w=[1,1,1,1,1,1,1,1];function D(o){let t=4294967295&o;for(let o=0;o<w.length;o+=1)t^=31415*w[o],w[o]=t>>>16^65535&t}D(2718281828),D(4590452353),D(I.length);for(let o=0;o<I.length;o+=1)D(I.charCodeAt(o));function $(o){let t=0;for(let r=0;r<w.length;r+=1){const n=t+o.length*w[r];w[r]=65535&n,t=n>>>16}return o[t]}function A(o,t){const f=`rotate(${$(r)}) scale(${$([-1,1])}, 1)`;o.appendChild(d("rect",{x:-8,y:-8,width:16,height:16,rx:5,transform:f,fill:g(t,$([-.5,1]),-1)})),o.appendChild(d("path",{d:`${$(n)} ${$(e)}`,transform:f,stroke:g(t,$([-.5,1]),1),"stroke-width":1,"stroke-linecap":"round",fill:"none"}))}function v(o,t,r,n,e,f,l){const i=m(t),x=m(r);console.assert(Math.abs(a(i,x))<.5,i,x);const g=c(i,x);let u=y(i);n&&(u=s(u,-1));const M=f[0].from-1,L=f[f.length-1].to+1;let p,C;a(u,x)>0?(p=M,C=L):(p=L,C=M);const b={"--":{x:-8,v:u},"-":{x:p,v:x},0:{x:0,v:g},"+":{x:C,v:x},"++":{x:10,v:u}};function I(o,t){const r=m(o.v);return c(s(i,o.x/a(r,u)),s(r,t/a(r,u)))}l.forEach((t=>{e.forEach((r=>{const n=[h(I(b[t.from],r.from)),h(I(b[t.from],r.to)),h(I(b[t.to],r.to)),h(I(b[t.to],r.from))];o.appendChild(d("polygon",{points:n.join(" "),fill:"black"}))}))}))}function E(o){const t=[];for(let r=0;r<o;r+=1)t.push(r);const r=$(t),n=[];for(let o=0;o<r;o+=1)n.push({index:o,from:o,to:o+1});const e=$([0,1,2,3]);0===e?n.push({index:r,from:r,to:r+2}):1===e?n.push({index:r,from:r,to:r+1.3}):2===e?n.push({index:r,from:r+.7,to:r+2}):3===e&&(n.push({index:r,from:r,to:r+1}),n.push({index:r,from:r+1,to:r+2}));for(let t=r+1;t<o;t+=1)n.push({index:t,from:t+1,to:t+2});return n}const N=$(o),S=[[null,null],[null,null],[null,null]];for(let o=0;o<3;o+=1)for(let t=0;t<2;t+=1)S[o][t]=d("g",{});const k=$(f);let Z=$(l);for(let o=0;o<k.length;o+=1){let t,r;o+1<k.length?t=x(k[o+1],k[o]):(t=y(x(k[o-1],k[o])),$([!1,!0])&&(t=s(t,-1))),o-1>=0?r=x(k[o-1],k[o]):(r=y(x(k[o+1],k[o])),$([!1,!0])&&(r=s(r,-1)));const n=Z;Z=$(l);const e=$(i);v(S[k[o].y][k[o].x],t,r,!1,Z,n,e.a),v(S[k[o].y][k[o].x],r,t,!0,n,Z,e.b)}for(let o=0;o<3;o+=1)for(let t=0;t<2;t+=1)S[o][t].firstChild||A(S[o][t],N);b.setAttribute("viewBox","-2.1 -2.1 4.2 4.2");const j=$(t),P=d("g",{transform:`rotate(${j.rotation})scale(${j.reflection}, 1)`});P.appendChild(d("rect",{x:-2.05,y:-2.05,width:4.1,height:4.1,rx:.4,fill:g(N,1,1)}));const B=d("g",{transform:`translate(1.5, 1.5)scale(0.3, 0.3)scale(${j.reflection}, 1)rotate(${-j.rotation})`});B.appendChild(d("image",{x:-1,y:-1,witdh:2,height:2,href:p})),P.appendChild(B),P.appendChild(d("line",{x1:1.5,y1:-1.5,x2:1.5,y2:.8,stroke:"black","stroke-width":$([.1,.2,.4])})),b.appendChild(P);const R=E(2);E(3).forEach((o=>{R.forEach((t=>{const r=d("g",{transform:`translate(${.5*(t.from+t.to-4)} ${.5*(o.from+o.to-4)})scale(${.05*(t.to-t.from)} ${.05*(o.to-o.from)})`});r.appendChild(S[o.index][t.index].cloneNode(!0)),P.appendChild(r)}))}))}}();