Warping an Image into a Möbius Loop
A simple Python script to warp an image into a Möbius loop
Me and the rest of the organizers of SUMS 2025, a math symposium at Brown where we combine math + another field—in this case, music—were working on making a poster for the event.
I had heard that Bach did a lot of work with symmetries (reflection, inversion, etc.) in his music, and I had even heard that he incorporated a section that was essentially played on a Möbius loop. Since the loop is such a well-known visual, I thought it would be fun to make a poster with music warped into a Möbius loop.
I couldn’t find any good scripts to do this online, so I quickly bodged together a python script to do this.
The formula for a Möbius loop was pretty easy to come up with on Desmos:
def mobius(u, v, band_size=0.5):
def s1(u):
return np.array([cos(u), sin(u), 0])
def band(u, v):
return v * np.array([0, cos(u), sin(u)]) +
(1 - v) * np.array([0, -cos(u), -sin(u)])
return s1((tau * u)) +
(band(((tau * u) + (tau / 4)) / 2, v) * band_size)
But the rendering was a bit more difficult. Basically, it uses a 3D plot in matplotlib to render the loop, and for each cell in the grid (or mesh) on the loop, it finds the color of the pixel in the image that corresponds to that cell. The downside is that it takes a while to render for large images, but the upside is that you can actually rotate it around in the 3D plot.
Here’s the input image I used:
and here’s the output of the script, which is a 3D plot of the Möbius loop with the image warped around it: