Skip to content

Instantly share code, notes, and snippets.

@citylims
Created April 5, 2015 03:19
Show Gist options
  • Save citylims/7ee85c5f2e13a63043c0 to your computer and use it in GitHub Desktop.
Save citylims/7ee85c5f2e13a63043c0 to your computer and use it in GitHub Desktop.
function frame(){
$.fillStyle = "hsla(0,5%,5%,1)";
$.fillRect(0, 0, w, h);
$.fillStyle = "hsla(" + (ŭ % 360) + ",100%,50%,1)";
$.globalAlpha = .8;
var gravX = msX;
var gravY = msY;
var f = first;
do {
var dX = gravX - f.x;
var dY = gravY - f.y;
var a = 20 / (dX * dX + dY * dY);
var aX = a * dX;
var aY = a * dY;
f.vel_x += aX;
f.vel_y += aY;
f.x += f.vel_x;
f.y += f.vel_y;
f.vel_x *= 0.7;
f.vel_y *= 0.8;
if (f.x > w)
f.x = 0;
else if (f.x < 0)
f.x = w;
if (f.y > h)
f.y = 0;
else if (f.y < 0)
f.y = h;
$.fillRect(f.x,f.y,15,15);
}
while (f = f.next);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment