(window.webpackJsonp=window.webpackJsonp||[]).push([[63],{0:function(e,t,r){"use strict";var n=function(e,t,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===r&&(r=0),this.x=e,this.y=t,this.z=r};n.prototype.divide=function(e){if("number"!=typeof e)throw new Error("invalid input: "+e);return this.x/=e,this.y/=e,this.z/=e,this},n.prototype.cross=function(e){var t=this.x,r=this.y,i=this.z;if(!(e instanceof n))throw new Error("invalid input: "+e);this.x=r*e.z-i*e.y,this.y=i*e.x-t*e.z,this.z=t*e.y-r*e.x},n.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},n.prototype.normalize=function(){return this.divide(this.length())},t.a=n},1:function(e,t,r){"use strict";r.d(t,"c",function(){return i}),r.d(t,"d",function(){return a}),r.d(t,"a",function(){return o}),r.d(t,"b",function(){return s});var n=r(0);function i(e,t,r,n){for(var i,a,o,s=(n=Object.assign({},{size:10,color:[.5,.5,1,1],translation:[0,0,0],textured:!1},n)).size,f=n.color,u=n.translation,h=n.textured,l=[],c=[],d=t.trianglesNormalBuffers,v=t.trianglesColorBuffers,m=t.trianglesVerticeBuffers,p=t.trianglesTexCoordBuffers,A=t.vertexIndexBuffers,R=0;R<5;++R)l.push(0),l.push(1),l.push(0),c.push(f[0]),c.push(f[1]),c.push(f[2]),c.push(f[3]);i=[0,0,0,-s,0,-s,s,0,-s,s,0,s,-s,0,s],o=[0,0,-s,-s,s,-s,s,s,-s,s];for(var g=0;g<i.length;g+=3)i[g]+=u[0],i[g+1]+=u[1],i[g+2]+=u[2];a=[0,1,2,0,2,3,0,3,4,0,4,1],d[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,d[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(l),e.STATIC_DRAW),d[r].itemSize=3,d[r].numItems=l.length/3,v[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,v[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(c),e.STATIC_DRAW),v[r].itemSize=4,v[r].numItems=c.length/4,m[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,m[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(i),e.STATIC_DRAW),m[r].itemSize=3,m[r].numItems=i.length/3,h&&(p[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,p[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(o),e.STATIC_DRAW),p[r].itemSize=2,p[r].numItems=o.length/2),A[r]=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,A[r]),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array(a),e.STREAM_DRAW),A[r].itemSize=3,A[r].numItems=a.length}function a(e,t,r,i){for(var a=(i=Object.assign({},{color:[1,0,0,1],translation:[0,0,0],radius:1,division:30,smoothShading:!0,textured:!1},i)).color,o=i.translation,s=i.radius,f=i.division,u=i.smoothShading,h=i.textured,l=f,c=f,d=[],v=[],m=[],p=[],A=[],R=t.trianglesNormalBuffers,g=t.trianglesColorBuffers,B=t.trianglesVerticeBuffers,x=t.trianglesTexCoordBuffers,b=t.vertexIndexBuffers,E=0;E<=l;E++)for(var F=E*Math.PI/l,y=Math.sin(F),M=Math.cos(F),_=0;_<=c;_++){var w=2*_*Math.PI/c,S=Math.sin(w),I=Math.cos(w)*y,T=M,U=S*y;A.push(.5*(I+1)),A.push(.5*(T+1)),m.push(I),m.push(T),m.push(U),v.push(a[0]),v.push(a[1]),v.push(a[2]),v.push(a[3]),d.push(s*I+o[0]),d.push(s*T+o[1]),d.push(s*U+o[2])}for(var D=0;D<l;D++)for(var Y=0;Y<c;Y++){var z=D*(c+1)+Y,L=z+c+1;p.push(z),p.push(L),p.push(z+1),p.push(L),p.push(L+1),p.push(z+1)}if(!u){d=function(e,t){for(var r=[],n=0;n<t.length;++n){var i=3*t[n];r.push(e[i]),r.push(e[i+1]),r.push(e[i+2])}return r}(d,p),v=[];for(var C=0;C<p.length;++C)v.push(a[0]),v.push(a[1]),v.push(a[2]),v.push(a[3]);m=function(e,t){for(var r=[],i=0;i<t.length;i+=3){var a=3*t[i],o=3*t[i+1],s=3*t[i+2],f=new n.a(e[a],e[a+1],e[a+2]),u=new n.a(e[o],e[o+1],e[o+2]),h=new n.a(e[s],e[s+1],e[s+2]),l=(f.x+u.x+h.x)/3,c=(f.y+u.y+h.y)/3,d=(f.z+u.z+h.z)/3,v=new n.a(l,c,d);r.push(v.x),r.push(v.y),r.push(v.z),r.push(v.x),r.push(v.y),r.push(v.z),r.push(v.x),r.push(v.y),r.push(v.z)}return r}(m,p)}R[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,R[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(m),e.STATIC_DRAW),R[r].itemSize=3,R[r].numItems=m.length/3,g[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,g[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(v),e.STATIC_DRAW),g[r].itemSize=4,g[r].numItems=v.length/4,B[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,B[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(d),e.STATIC_DRAW),B[r].itemSize=3,B[r].numItems=d.length/3,h&&(x[r]=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,x[r]),e.bufferData(e.ARRAY_BUFFER,new Float32Array(A),e.STATIC_DRAW),x[r].itemSize=2,x[r].numItems=A.length/2),b[r]=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,b[r]),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array(p),e.STREAM_DRAW),b[r].itemSize=3,b[r].numItems=p.length}function o(e,t,r,n){void 0===r&&(r=1),void 0===n&&(n=10);for(var i=r/n,a=[],o=0;o<=n;++o)for(var s=0;s<=n;++s)a.push(o*i),a.push(0),a.push(s*i);for(var f=[0],u=0;u<n;++u)if(u%2==0)for(var h=0;h<=n;++h)0!==h&&f.push(u*(n+1)+h),f.push((u+1)*(n+1)+h);else for(var l=0;l<=n;++l)0!==l&&f.push((u+1)*(n+1)-(l+1)),f.push((u+2)*(n+1)-(l+1));t.trianglesVerticesBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,t.trianglesVerticesBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array(a),e.STATIC_DRAW),t.trianglesVerticesBuffer.itemSize=3,t.trianglesVerticesBuffer.numItems=a.length/3,t.vertexIndexBuffer=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.vertexIndexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array(f),e.STREAM_DRAW),t.vertexIndexBuffer.itemSize=3,t.vertexIndexBuffer.numItems=f.length}function s(e,t,r,n){void 0===r&&(r=1),void 0===n&&(n=3);for(var i=Math.pow(2,n),a=r/i,o=[],s=0;s<=i;++s)for(var f=0;f<=i;++f)o.push(s*a-.5*r),o.push(0),o.push(f*a-.5*r);o[3*(0+0*(i+1))+1]=1.5,o[3*(i+0*(i+1))+1]=3.5,o[3*(0+i*(i+1))+1]=2,o[3*(i+i*(i+1))+1]=1,function e(t,r,n,i,a,o,s){if(r[0]+1===a[0]||r[1]+1===a[1])return;var f=[(r[0]+a[0])/2,(r[1]+a[1])/2];var u=[r[0],(r[1]+i[1])/2];var h=[n[0],(n[1]+a[1])/2];var l=[(r[0]+n[0])/2,r[1]];var c=[(i[0]+a[0])/2,i[1]];var d=t[3*(r[0]+r[1]*(o+1))+1];var v=t[3*(n[0]+n[1]*(o+1))+1];var m=t[3*(i[0]+i[1]*(o+1))+1];var p=t[3*(a[0]+a[1]*(o+1))+1];var A=(d+v)/2;t[3*(l[0]+l[1]*(o+1))+1]=A;var R=(m+p)/2;t[3*(c[0]+c[1]*(o+1))+1]=R;var g=(d+m)/2;t[3*(u[0]+u[1]*(o+1))+1]=g;var B=(v+p)/2;t[3*(h[0]+h[1]*(o+1))+1]=B;t[3*(f[0]+f[1]*(o+1))+1]=(d+v+m+p)/4+(-.5+Math.random())*Math.pow(.65,s-2);e(t,r,l,u,f,o,s+1);e(t,l,n,f,h,o,s+1);e(t,u,f,i,c,o,s+1);e(t,f,h,c,a,o,s+1)}(o,[0,0],[i,0],[0,i],[i,i],i,0);for(var u=[0],h=0;h<i;++h)if(h%2==0)for(var l=0;l<=i;++l)0!==l&&u.push(l+h*(i+1)),u.push(l+(h+1)*(i+1));else for(var c=0;c<=i;++c)0!==c&&u.push((h+1)*(i+1)-(c+1)),u.push((h+2)*(i+1)-(c+1));t.trianglesVerticesBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,t.trianglesVerticesBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array(o),e.STATIC_DRAW),t.trianglesVerticesBuffer.itemSize=3,t.trianglesVerticesBuffer.numItems=o.length/3,t.vertexIndexBuffer=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.vertexIndexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array(u),e.STREAM_DRAW),t.vertexIndexBuffer.itemSize=3,t.vertexIndexBuffer.numItems=u.length}},3:function(e,t,r){"use strict";r.d(t,"b",function(){return i}),r.d(t,"c",function(){return a}),r.d(t,"a",function(){return o});var n=r(0),i=function(e){e=Object.assign({},{radius:1,position:new n.a(0,0,0),velocity:new n.a(0,0,0),acceleration:new n.a(0,0,0)},e),this.radius=e.radius,this.position=e.position,this.velocity=e.velocity,this.acceleration=e.acceleration,this.vboIndex=e.vboIndex,this.totalVelocity=0},a=function(e){e=Object.assign({},{startX:0,startY:0,endX:0,endY:0},e),this.slope=0,(e.endX-e.startX>1e-4||e.endX-e.startX<-.001)&&(this.slope=(e.endY-e.startY)/(e.endX-e.startX)),this.startX=e.startX,this.startY=e.startY,this.endX=e.endX,this.endY=e.endY;var t=[e.startX-e.endX,e.startY-e.endY];this.angle=0,this.angle=Math.atan2(t[1],t[0])},o=function(e,t){void 0===e&&(e=[.1*(Math.random()-.5),.1*(Math.random()-.5),.1*(Math.random()-.5)]),void 0===t&&(t=[1,0,0,.5]),this.position=e,this.color=t,this.velocity=[.1*(Math.random()-.5),.1*(Math.random()-.5),.1*(Math.random()-.5)],Math.abs(this.velocity[0])<.01&&Math.abs(this.velocity[1])<.01&&Math.abs(this.velocity[2])<.01&&(this.velocity[0]=.1),this.age=0,this.lifespan=20,this.size=1};o.prototype.update=function(){this.position[0]+=.1*this.velocity[0],this.position[1]+=.1*this.velocity[1],this.position[2]+=.1*this.velocity[2];var e=Math.abs(this.position[0]),t=Math.abs(this.position[1]),r=Math.abs(this.position[2]);e*e+t*t+r*r>4&&(this.position=[2*Math.random()-1,2*Math.random()-1,2*Math.random()-1],this.velocity=[2*Math.random()-1,2*Math.random()-1,2*Math.random()-1],this.age<10?this.color=[1,1,1,.75]:this.age<this.lifespan?this.color=[0,0,1,.75]:this.color=[1,1,1,0],this.age++)}},66:function(e,t,r){"use strict";r.r(t);var n=r(1),i=r(3),a=r(0),o=null,s=null,f=null,u=null,h=null,l=null,c=null,d=null,v=null,m=[],p=[],A=[],R=[],g=mat4.create(),B=mat4.create(),x=mat3.create(),b=!1,E={flat:{vertexShader:"\n    attribute vec3 aVertexPosition;\n    attribute vec3 aVertexColor;\n    attribute vec3 aVertexNormal;\n\n    uniform mat4 uPMatrix;    \n    uniform mat4 uMVMatrix;\n    uniform mat3 uNormalMatrix;\n    \n    varying highp vec3 vColor;\n    varying highp vec3 L;\n    varying highp vec3 N;\n    \n    void main(void) {\n      gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n      \n      vec3 pointLightPosition = vec3(1.0, 2.0, -1.0);\n      vec3 pointLightDirection = normalize(vec3(pointLightPosition.xyz - aVertexPosition.xyz));\n      vec3 ambientColor = vec3(0.1, 0.1, 0.1);\n      \n      L = vec3(uPMatrix * uMVMatrix * vec4(pointLightDirection, 1.0));\n      N = uNormalMatrix * aVertexNormal;\n      \n      vColor = aVertexColor;\n    }\n  ",fragmentShader:"\n    varying highp vec3 vColor;\n    varying highp vec3 N;\n    varying highp vec3 L;\n    \n    void main(void) {\n      highp float lambert = max(dot(normalize(N), normalize(L)), 0.0);\n      gl_FragColor = vec4(vColor * lambert, 1.0);\n    }\n  "}},F=[],y=1,M=5,_=-1,w=-.8;function S(e,t){var r=o.createShader(t);return o.shaderSource(r,e),o.compileShader(r),o.getShaderParameter(r,o.COMPILE_STATUS)||alert("Error compiling shader: "+o.getShaderInfoLog(r)),r}function I(e,t){for(var r=0;r<e.length;r++)if(e[r].vboIndex===t)return r;return-1}function T(e){var t=F[e];return M-(t.position.y+t.radius)>_}function U(){o.uniformMatrix4fv(u.pMatrixUniform,!1,g),o.uniformMatrix4fv(u.mvMatrixUniform,!1,B),o.uniformMatrix3fv(u.normalMatrixUniform,!1,x)}window.addEventListener("load",function(){s=document.querySelector("#canvas"),f=document.querySelector("#container"),s.width=f.clientWidth,s.height=f.clientHeight,function(){var e=function(e){e>0?y+=1:(y-=.1)<.01&&(y=.1)};s.addEventListener("mousewheel",function(t){t.stopPropagation(),t.preventDefault(),e(t.wheelDelta)}),s.addEventListener("DOMMouseScroll",function(t){t.stopPropagation(),t.preventDefault(),e(-.1*t.originalEvent.detail)})}();try{o=s.getContext("webgl")||s.getContext("experimental-webgl")}catch(e){console.error(e)}o&&(!function(e){(function(e,t){var r=E[t].vertexShader,n=E[t].fragmentShader;l=S(r,o.VERTEX_SHADER),h=S(n,o.FRAGMENT_SHADER),o.attachShader(e,l),o.attachShader(e,h),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)||alert("Unable to initialize the shader program.")})(u=o.createProgram(),e),o.useProgram(u),u.pMatrixUniform=o.getUniformLocation(u,"uPMatrix"),u.mvMatrixUniform=o.getUniformLocation(u,"uMVMatrix"),u.normalMatrixUniform=o.getUniformLocation(u,"uNormalMatrix")}("flat"),Object(n.d)(o,{trianglesNormalBuffers:p,trianglesColorBuffers:A,trianglesVerticeBuffers:m,vertexIndexBuffers:R},0,{color:[1,0,0,1],division:20,smoothShading:!1}),Object(n.d)(o,{trianglesNormalBuffers:p,trianglesColorBuffers:A,trianglesVerticeBuffers:m,vertexIndexBuffers:R},1,{color:[0,1,0,1],division:10,smoothShading:!1}),Object(n.d)(o,{trianglesNormalBuffers:p,trianglesColorBuffers:A,trianglesVerticeBuffers:m,vertexIndexBuffers:R},2,{color:[1,1,0,1],division:5,smoothShading:!1}),Object(n.d)(o,{trianglesNormalBuffers:p,trianglesColorBuffers:A,trianglesVerticeBuffers:m,vertexIndexBuffers:R},3,{color:[1,0,1,1]}),Object(n.d)(o,{trianglesNormalBuffers:p,trianglesColorBuffers:A,trianglesVerticeBuffers:m,vertexIndexBuffers:R},4,{color:[0,1,1,1]}),Object(n.c)(o,{trianglesNormalBuffers:p,trianglesColorBuffers:A,trianglesVerticeBuffers:m,vertexIndexBuffers:R},5,{translation:[0,_,0]}),F.push(new i.b({vboIndex:0,position:new a.a(-1,-.75,0),acceleration:new a.a(0,.01,0)})),F.push(new i.b({vboIndex:1,position:new a.a(0,0,1),acceleration:new a.a(0,.01,0)})),F.push(new i.b({vboIndex:2,position:new a.a(1,.25,-1),acceleration:new a.a(0,.01,0)})),F.push(new i.b({vboIndex:3,position:new a.a(-1,1,-1),acceleration:new a.a(0,.01,0)})),F.push(new i.b({vboIndex:4,position:new a.a(-0,1.75,-0),acceleration:new a.a(0,.01,0)})),c=o.getAttribLocation(u,"aVertexPosition"),v=o.getAttribLocation(u,"aVertexColor"),d=o.getAttribLocation(u,"aVertexNormal"),o.enableVertexAttribArray(c),o.enableVertexAttribArray(v),o.enableVertexAttribArray(d),function e(){b||(o.clearColor(.7,.7,.7,1),o.clear(o.COLOR_BUFFER_BIT|o.DEPTH_BUFFER_BIT),o.enable(o.DEPTH_TEST),o.viewport(0,0,s.width,s.height),mat4.perspective(g,45,s.width/s.height,.1,100),function(){for(var e=0;e<R.length;++e){mat4.identity(B),mat4.translate(B,B,[0,-1,-15.5]);var t=I(F,e);if(-1!==t){var r=F[t];T(t)?(r.velocity.y+=r.acceleration.y,r.position.y+=r.velocity.y):(r.position.y-=r.velocity.y,r.velocity.y*=w),mat4.translate(B,B,[r.position.x,M-r.position.y,r.position.z])}mat4.scale(B,B,[y,y,y]);var n=mat3.create();mat3.fromMat4(n,B),mat3.invert(x,n),mat3.transpose(x,x),U(),o.bindBuffer(o.ARRAY_BUFFER,m[e]),o.vertexAttribPointer(c,3,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,A[e]),o.vertexAttribPointer(v,4,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,p[e]),o.vertexAttribPointer(d,3,o.FLOAT,!1,0,0),4===e?(o.disable(o.DEPTH_TEST),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE),o.blendEquation(o.FUNC_ADD)):(o.disable(o.BLEND),o.enable(o.DEPTH_TEST)),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,R[e]),e>2?o.drawElements(o.TRIANGLES,R[e].numItems,o.UNSIGNED_SHORT,0):o.drawArrays(o.TRIANGLES,0,m[e].numItems)}}()),requestAnimationFrame(e)}())}),document.addEventListener("keyup",function(e){switch(e.keyCode){case 80:b=!b}})}},[[66,0]]]);
//# sourceMappingURL=webgl-physics-gravity.js.map