u/Altruistic_Lawyer608

Infinite Recursion in Real-Time: A Python + MLX implementation of the Droste Effect

Hi everyone!

Like many of you, I was mesmerized by Grant’s video on "Conformal Mapping and the Droste Effect." There was something so satisfying about the way he visualized the math behind M.C. Escher’s Print Gallery, turning a complex grid into a perfect, infinite loop.

Inspired by that video, I decided to build a real-time engine to explore this effect.

How it works:

The engine uses the conformal mapping $w = z^a$ (specifically the logarithmic form $w = \exp(a \cdot \log(z) + b)$) to warp images into a spiral. To make it smooth enough for a "gallery" style projection, I used Apple’s MLX framework for GPU acceleration.

Key Features:

  • GIF Generation: The tool now includes the ability to export your recursive animations directly as GIFs, making it easy to capture and share the infinite loops you create.
  • Centering & Projection: I built a separate control UI so I can project the clean animation onto a wall while managing the math on a second monitor.
  • Performance: Achieves ~60fps at 1080p using MLX's lazy evaluation on Apple Silicon.

Source Code:

I've open-sourced the implementation here if anyone wants to play with the math or try it with their own images:

👉https://github.com/aliotta/conformal

Technical Specs:

  • Math: Logarithmic spiral mapping via complex numbers.
  • Hardware: Optimized for Apple Silicon using the MLX framework.

Huge thanks to the 3Blue1Brown team for making the math feel so intuitive. Watching the video is one thing, but actually seeing the coordinates "twist" in real-time as you move the sliders is a whole different level of appreciation for the math!

Would love to hear any feedback or ideas on how to take the conformal mapping even further!

u/Altruistic_Lawyer608 — 2 days ago

From Video to Code: Recreating the Infinite Droste Spiral with Python and MLX

Hi everyone!

Like many of you, I was mesmerized by Grant’s video on "Conformal Mapping and the Droste Effect." There was something so satisfying about the way he visualized the math behind M.C. Escher’s Print Gallery, turning a complex grid into a perfect, infinite loop.

Inspired by that video and this incredible Reddit comment by u/Not_A_Robot_I_Swear, I decided to build a real-time engine to explore this effect using my own source images.

How it works:

The engine uses the conformal mapping $w = z^a$ (specifically the logarithmic form $w = \exp(a \cdot \log(z) + b)$) to warp the image into a spiral. To make it smooth enough for a "gallery" style projection on my wall, I used Apple’s MLX framework for GPU acceleration.

Key Features:

  • Dual-Layer Blending: To solve the "pixelation" problem as you zoom in, the script renders two concentric layers simultaneously and blends them with a radial mask. This ensures the "center" always looks sharp.
  • Centering & Projection: I built a separate control UI so I can project the clean animation onto a wall while managing the math on a second monitor.
  • Performance: ~60fps at 1080p using MLX's lazy evaluation on Apple Silicon.

Source Code:

I've open-sourced the implementation here if anyone wants to play with the math or try it with their own images:

👉https://github.com/aliotta/conformal

Technical Specs:

  • Math: Logarithmic spiral mapping via complex numbers.
  • Fidelity: 2138x1600 PNG source (Escher's "Eye") with a recursion seed baked into the pupil.

Huge thanks to the 3Blue1Brown team for making the math feel so intuitive. Watching the video is one thing, but actually seeing the coordinates "twist" in real-time as you move the sliders is a whole different level of appreciation for Escher's genius!

Would love to hear any feedback or ideas on how to take the conformal mapping even further!

u/Altruistic_Lawyer608 — 5 days ago