Created
August 8, 2014 16:47
-
-
Save imack/be25ecf0407200f009bf to your computer and use it in GitHub Desktop.
Ian's bobble Head Xmas Card
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
// Position Variables | |
var x = 0; | |
var y =0; | |
var initial_x = 169; | |
var initial_y = 111; | |
// Speed - Velocity | |
var vx = 0; | |
var vy = 0; | |
// Acceleration | |
var ax = 0; | |
var ay = 0; | |
// spin | |
var kx = 0; | |
var ky = 0; | |
var delay = 0.1; | |
var vMultiplier = 0.5; | |
window.ondevicemotion = function(event) { | |
ax = event.accelerationIncludingGravity.x; | |
ay = event.accelerationIncludingGravity.y + 9.5; | |
} | |
setInterval(function() { | |
kx = -0.05 * x; | |
ky = -0.2 * y; | |
acceleration_x = ax /5.0; | |
acceleration_y = ay /5.0; | |
var x_dampen = -0.1 * vx ; | |
var y_dampen = -0.1 * vy ; | |
vx = vx + acceleration_x + kx + x_dampen; | |
x = x + vx; | |
vy = vy + acceleration_y + ky + y_dampen; | |
y = y + vy; | |
abs_x = Math.abs( x ); | |
//$("#text").html( ay + "<br>" + acceleration_y); | |
$("#ian_head").css("left", (initial_x + x) + "px"); | |
$("#ian_head").css("top", (initial_y - y) + "px"); | |
//$("#ian_head").css("top", (initial_y + ( abs_x /5.0)) + "px"); | |
}, delay); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment