So visualize the moving Earth in the center of each image with the other respective planet moving relative to the Earth. Since both are moving and rotating about the Sun we get these interesting motions with a lot of structure.
This is the theory of epicycles which was the main theory of the motion of the planets before the heliocentric view became prominent.
https://www.youtube.com/watch?v=BmbuSR-fOZM
https://en.wikipedia.org/wiki/3753_Cruithne
Cruithne orbits the sun at about the same distance as the Earth, and so with about the same period as the Earth. The orbit varies, so sometimes it's closer to the sun than we are, and sometimes further from it. So, seen from the Earth, what it's doing is moving around us - sometimes ahead of us in orbit, sometimes sunward, sometimes behind us, sometimes starward. But its orbit isn't pefectly elliptical, and it has more inclination, so it traces out an interesting path.
That video is a recycling of an older video which had a very informative voice-over, rather than some cheesy music. That video doesn't seem to be online any more, sadly.
Cruithne's orbit was only figured out in 1997, and i remember that it was briefly very cool (for small values of cool). Stephen Baxter, who was a top science fiction writer at the time, featured it in his novel 'Time'.
https://earthsky.org/space/what-is-retrograde-motion kind of gives you an idea
(Which can be summed up into "something something resonance something something dimensions".)