Skip to content

Instantly share code, notes, and snippets.

@marr
Created January 27, 2017 03:25
Show Gist options
  • Save marr/308ee6861a46d2ba48db6efe8593e496 to your computer and use it in GitHub Desktop.
Save marr/308ee6861a46d2ba48db6efe8593e496 to your computer and use it in GitHub Desktop.
var PIBY2 = Math.PI / 2;
var ToDegrees = 180 / Math.PI;
var x = 50;
var y = 50;
var vx = Math.random() - 0.5;
var vy = Math.random() - 0.5;
function update() {
vx += Math.random() * 0.5 - 0.25;
vy += Math.random() * 0.5 - 0.25;
var newx = x + vx;
var newy = y + vy;
var dy = newy - y;
var dx = newx - x;
var a = (Math.atan2(dy, dx) + PIBY2) * ToDegrees; // The new target rotation in degrees
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment