Javascipt physics code