# PixAnvil Megaparticle Gravity demo

Er, JavaScript or WebGL doesn't seem to be running, so basically all you're going to see is the bare code...

 // We find neighbors by looking them up in this hash var hash={}; var hashscale=4.0; // multiply XYZ by this to get to hash var hashsize=1.0/hashscale; // Return the hash element for this vector var hashVec3=function(P) { var x=Math.floor(P.x*hashscale); var y=Math.floor(P.y*hashscale); //var z=Math.floor(P.z*hashscale); var x_y=x+"_"+y; // int to string var h=hash[x_y]; if (h) // already exists return h; else { // need to create it h=new Array; hash[x_y]=h; return h; } } // Add the gravitational force to F // exerted on P by its neighbor N, mass mN var gravity=function(F,P,N,mN,soften) { var R=P.m(N); // them to us var Rlen=R.length(); /* f = G m1 m2 / r^2 F = Gmm * (R / r) * /r^2 F = Gmm * R / r^3 */ var G=0.002; // gravity constant * mass1 F.add(R.t(-G*mN/(soften+Rlen*Rlen*Rlen))); } var megaP=new vec3(0,0,0); // total position var megaM=0.0; // total mass // Add each particle to the hash for (var i=0;i