_='(i a.style="widMj%;hEjvh;:left",g)g[i[0]+i[6]]=g[i];wiMO.u=g.G1f,x=y=k=g)p=cP(35633"tribute 2 p gl_Posit=4?FN"precis mediump ;G Zt,a,x,y Uf`ord.rg/64!-.f.=a;Zc=+xz,v=+yz;m2 m$cc-cc)s$vv-vv)fJf#Ur`Q,,r+`t*2.,t,-2.rJr#Zg=.1,b=Q;Ui`!Kl=Rl<2Rl++){Uo=r+f*;oQ)-mod(o,2.))Ze,n=e=!;Kd=Rd<2Rd++)oo)/dot(o,o)-3,n+o)-ee=oif(l>6)Q-max(!,.3-i+=b+g,g,g)*n*5*b;.73;g+=.1;}i=mix(i)i,.85lor=4(i*.01.lo?ug?bfO=34962,cB()eV(0vA(2,5120bDO,Tw Int8Array([|,|]35044o=,(Lt@-oa@TrHE/TrWidMx@xy@ydr(6,3requestAnimFrame(L)})(down=upk^=1},movek&&(xX,yY)};),3=funct(e){uOf?,"flo}@ce(saS?,slengM(onmouse ;void ma(){Tw De/1e5);incos(for=abs(gl_FragCo,1g*(sS(s=cS(n*n*.001at.5vecionb*=s(=e.page0,!0.#.r=s;$=m2(?(p@"EeightGunimJ.rm;K(t MthO(gQ1.R0;TneU Z `=j:100z/50!|-3';for(Y in $='|zj`ZUTRQOMKJGE@?$#! ')with(_.split($[Y]))_=join(pop());eval(_)
// see full at https://github.com/denys-potapov/js1k
/*
JS1K's shim gives the following vars for free:
- a: canvas element
- b: body
- d: document
- g: webgl context for the canvas.
*/
// GUI: canvas
a.style='width:100%;height:100vh;float:left';
// Canvas methods hashing:
// This loop creates tiny shortcuts for all the webgl context's methods/constants we need:
// createProgram => cP
// shaderSource => sS
// createShader => cS
// compileShader => ce
// attachShader => aS
// linkProgram => lo
// useProgram => ug
// bindBuffer => bf
// createBuffer => cB
// enableVertexAttribArray => eV
// vertexAttribPointer => vA
// bufferData => bD
// getUniformLocation => gf
// drawArrays => dr
// NO_ERROR => NO (value = 0)
// FRAGMENT_SHADER => FN (value: 35632)
// ELEMENT_ARRAY_BUFFER_BINDING => ET (value: 34965)
// We need to redefine the webgl context because adding the textarea in the DOM rewrote the canvas "a".
for(i in g){
g[i[0] + i[6]] = g[i];
}
// we use only one uniofrom
g.u = g.uniform1f;
// Mouse input:
// k: mouse down (0 / 1)
// x,y: mouse cords
x=y=k=0;
// Use the WebGL context's scope for all the following code
with(g){
// Define a new program
// p=createProgram();
p=cP();
// Basic vertex shader
// shaderSource(s=createShader(VERTEX_SHADER),"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}");
sS(s=cS(35633),'attribute vec2 p;void main(){gl_Position=vec4(p,1,1);}');
// Compile and attach it to the program
// compileShader(s);
ce(s);
//attachShader(p,s);
aS(p,s);
// Main program
// shaderSource(s=createShader(FRAGMENT_SHADER),'...');
sS(s=cS(FN),'uniform float t,a,x,y;void main(){vec3 f=vec3(gl_FragCoord.rg/640.-.5,1.);f.g*=a;float c=.5+x/500.,v=.5+y/500.;mat2 m=mat2(cos(c),sin(c),-sin(c),cos(c)),s=mat2(cos(v),sin(v),-sin(v),cos(v));f.rb*=m;f.rg*=s;vec3 r=vec3(1.,.5,.5);r+=vec3(t*2.,t,-2.);r.rb*=m;r.rg*=s;float g=.1,b=1.;vec3 i=vec3(0.);for(int l=0;l<20;l++){vec3 o=r+g*f*.5;o=abs(vec3(1.)-mod(o,vec3(2.)));float e,n=e=0.;for(int d=0;d<20;d++)o=abs(o)/dot(o,o)-.53,n+=abs(length(o)-e),e=length(o);if(l>6)b*=1.-max(0.,.3-n*n*.001);i+=b+vec3(g,g*g,g*g*g*g)*n*n*n*.0015*b;b*=.73;g+=.1;}i=mix(vec3(length(i)),i,.85);gl_FragColor=vec4(i*.01,1.);}');
// Compile and attach it to the program
// compileShader(s);
ce(s);
// DEBUGS
if (!g.getShaderParameter(s, g.COMPILE_STATUS)) {
g.getShaderInfoLog(s).trim().split("\n").forEach(ss =>
console.warn("[shader] " + ss))
throw new Error("Error while compiling shader")
};
// attachShader(p,s);
aS(p,s);
// Link and start the program
//linkProgram(P);
lo(p);
//useProgram(p);
ug(p);
// Define a big triangle the canvas, containing the viewport
// bindBuffer(g=ARRAY_BUFFER, createBuffer());
bf(g=34962,cB());
// enableVertexAttribArray(0);
eV(0);
// vertexAttribPointer(0, 2, BYTE, 0, 0, 0);
vA(0,2,5120,0,0,0);
// bufferData(g,new Int8Array([-3, 1, 1, -3, 1, 1]), STATIC_DRAW);
bD(g,new Int8Array([-3,1,1,-3,1,1]),35044);
// Start time (in seconds)
o = (new Date / 1e5);
// Main loop
(L=function(e){
// Current playback time (in 1/200 seconds)
u(gf(p,'t'), (new Date / 1e5) - o);
// Current sapect ration
u(gf(p,'a'), innerHeight / innerWidth);
// Mouse coordinates
u(gf(p,'x'), x);
u(gf(p,'y'), y);
// Draw
// drawArrays(TRIANGLE_FAN,0,3);
dr(6,0,3);
// Next frame
requestAnimationFrame(L);
})();
}
// Toggle d on mouse down / up
onmousedown=onmouseup=function(e){k^=1}
// Update iMouse on mouse move / click, according to z.
onmousemove=function(e){if(k)x=e.pageX,y=e.pageY}