Enable turbo mode for a smooth animation (press the green flag while holding shift).
I copied most of the stuff from my Desmos graph: https://www.desmos.com/calculator/zidpvfy7oc I got the rotation functions from Wikipedia's basic 3D rotation matrices: https://en.wikipedia.org/wiki/Rotation_matrix#Basic_3D_rotations