Coding a Glowing Möbius Strip: Non-Orientable Surfaces in Py5

2026/8/1

Visualizing complex topology is one of the most rewarding challenges in generative art. In this project, the goal was to create a digital representation of the classic Möbius strip—an infinite, non-orientable mathematical surface with only one side—and breathe life into it with flowing lines of neon energy. The result is an impossible geometry that continuously folds in on itself while glowing vibrantly in the darkness.Python, paired with the Py5 library, provides an excellent environment for this kind of work. It allows us to translate dense parametric equations directly into beautifully lit 3D geometry in real-time, bridging the gap between pure mathematics and visual expression.

Visual and Aesthetic Approach

To emphasize the infinite, looping nature of the Möbius strip, the surface isn't rendered with a flat, solid texture. Instead, it is constructed from a dense grid of semi-transparent quadrilaterals that utilize additive blending (py5.blend_mode(py5.ADD)).Sine and cosine waves modulate the color and opacity along the strip's UV parameters. This creates the illusion of bright energy waves pulsing continuously along the surface, tracing its twisted path. Set against a dark, obsidian violet background, the overlapping semi-transparent layers accumulate brightness, resulting in a luminous, neon aesthetic that feels simultaneously digital and organic.

Code and Technical Breakdown

The core geometry is generated by evaluating the parametric equations of a Möbius strip. We iterate over two variables: u (the angle around the circle) and v(the width across the strip).
# Draw Mobius strip using a dense grid
steps_u = 200
steps_v = 40
R = py5.height * 0.4

t = py5.frame_count * 0.05

py5.begin_shape(py5.QUADS)
for i in range(steps_u):
    u1 = py5.TWO_PI * i / steps_u
    u2 = py5.TWO_PI * (i + 1) / steps_u
    
    for j in range(steps_v):
        v1 = py5.remap(j, 0, steps_v, -R*0.3, R*0.3)
        v2 = py5.remap(j + 1, 0, steps_v, -R*0.3, R*0.3)
For every tiny segment defined by (u, v), we calculate its 3D Cartesian coordinates. The twist of the Möbius strip is achieved by the u / 2 term in the equations below, which ensures that after one full revolution (u = 2π), the strip has only twisted by 180 degrees (π).
# Parametric Mobius equations
def mobius(u, v):
    x = (R + v * math.cos(u / 2)) * math.cos(u)
    y = (R + v * math.cos(u / 2)) * math.sin(u)
    z = v * math.sin(u / 2)
    return x, y, z

x1, y1, z1 = mobius(u1, v1)
x2, y2, z2 = mobius(u2, v1)
x3, y3, z3 = mobius(u2, v2)
x4, y4, z4 = mobius(u1, v2)
Once the four vertices of the current quadrilateral are calculated, we apply the flowing energy effect. Rather than a static color, we calculate a `flow_val` that interferes two waves: one moving along the length of the strip (u1), and another moving across its width (v1), both driven by the animation time t.
        # Flowing energy lines effect
        flow_val = (math.sin(10 * u1 - t) + math.cos(5 * v1 + t)) * 0.5 + 0.5
        
        # Map the wave to Hue and Alpha
        hue = (280 + flow_val * 60 + py5.frame_count * 0.5) % 360
        alpha = py5.remap(flow_val, 0, 1, 20, 200)
        
        py5.fill(hue, 80, 100, alpha)
        
        # Draw the quad
        py5.vertex(x1, y1, z1)
        py5.vertex(x2, y2, z2)
        py5.vertex(x3, y3, z3)
        py5.vertex(x4, y4, z4)
        
py5.end_shape()
By mapping this interference pattern to both the `hue` and the alpha (opacity), we create dynamic, bright bands of light that sweep across the twisting surface. Because the strip is non-orientable, watching these lines travel seamlessly from the "outside" to the "inside" highlights the mathematical beauty of the shape.
abstract topological mobius strip 3d p1

Conclusion

Translating abstract topological concepts into visual art provides a tangible way to explore impossible geometries. The Möbius strip is a classic mathematical construct, but by treating it as a canvas for dynamic, generative light flows, it takes on a completely new, cybernetic identity. This project serves as a perfect example of how code can transform static math equations into breathing, animated sculptures.