How to get angle of rotation of object

why subtract the center twice ?

also, atan hs singularities/changes sign at ± 90 deg.
so your angle += 360 formula is wrong, too.