Created
January 27, 2017 03:25
-
-
Save marr/308ee6861a46d2ba48db6efe8593e496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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