The Lost Feed

🔬Weird Science

The Simple Python Code That Made a 3D Donut Spin

Discover the forgotten viral story of a tiny Python script that brought a spinning 3D donut to life, showing the power of signed distance functions.

1 views·6 min read·Jun 17, 2026
Signed distance functions in 46 lines of Python

Imagine seeing a complex, perfectly smooth 3D object spinning right on your computer screen. You might think it took a huge team of programmers and thousands of lines of code to make something so cool. But what if I told you a simple script, barely longer than a grocery list, could do it?

That's the strange story of a piece of Python code that surprised everyone. It created a beautiful, animated 3D donut, and it did it with an incredibly small amount of text. This forgotten viral gem showed just how much power can be packed into a few lines of code.

The Tiny Code That

Made a Big Splash

Back when people were always exploring new ways to make computer graphics, a very clever programmer shared something special. It was a Python script, so short you could read it in less than a minute. Yet, when you ran it, a smooth, spinning 3D donut appeared as if by magic.

This wasn't just a simple trick. It was a powerful demonstration of a concept called signed distance functions, or SDFs. Many people were truly amazed by how much visual complexity came from so little code. The script quickly became a popular example of elegant programming and clever math working together. It challenged the idea that great graphics always need huge programs.

What is a Signed Distance Function, Anyway?

Think of a signed distance function (SDF) like a special map for a shape. For any point in space, this function tells you two important things. First, it tells you exactly how far away that point is from the edge of your shape. Second, and crucially, it tells you if the point is inside or outside the shape.

If the distance it gives you is a positive number, you are outside the shape. If it's a negative number, you are definitely inside. And if the distance is exactly zero, you are right on the edge, the very surface of the object. This clever mathematical trick lets computers "understand" shapes in a very efficient way, without needing to store lots of individual points or triangles.

Building Complex Worlds with Simple Math

SDFs are incredibly useful for creating and combining shapes in computer graphics. Instead of describing every tiny part of an object, you describe its overall form using these distance rules. This makes it very easy to make smooth, complex designs that look very natural.

Imagine wanting to make a character with a round head and pointy ears. With SDFs, you can define the head as a simple sphere and the ears as basic cones. Then, you simply combine these functions using mathematical operations to "add" or "subtract" parts of shapes, or even blend them together smoothly. This method gives artists and programmers a lot of flexibility.

This approach is different from traditional methods that rely on meshes made of many small triangles. SDFs offer a smoother, more fluid way to think about shapes. They allow for easy changes and dynamic effects, which can be hard to achieve with fixed triangle models.

The Donut's Secret: Simple Shapes, Clever Math

The spinning donut script used this exact idea to bring its delicious-looking geometry to life. A donut shape, or a torus as it's known in math, can be quite tricky to describe in traditional 3D models. But with signed distance functions, you can define it using a relatively simple mathematical formula that tells you the distance to its surface.

The Python code then used this function to figure out which parts of the computer screen should show the donut. It rendered the donut pixel by pixel, calculating the distance for each point in the view. This is how it achieved such a smooth and realistic look with very little effort, making it appear solid and perfectly formed.

How the Donut

Spun and Shaded

Making the donut spin added another layer of cleverness to the tiny script. The code didn't just draw a static donut. It continuously updated its position and rotation based on time. This created the illusion of smooth, constant movement, all calculated on the fly by the computer.

Beyond just spinning, the script also made the donut look like it had light hitting it. It did this by calculating the "normal" (the direction the surface is facing) at each point. This normal information, combined with a simulated light source, allowed the script to create realistic shading and depth. This kind of real-time rendering from basic mathematical functions was, and still is, impressive for such a small program.

The Lasting

Impact of a Few Lines of Code

This small Python script resonated with many people in the programming and graphics communities. It wasn't just about making a donut; it was about showing the elegance and power of procedural generation. This is where content, like shapes, textures, or even entire worlds, is created by algorithms and mathematical rules rather than being drawn or modeled by hand.

It inspired a new wave of interest in minimalist programming and mathematical art. Many programmers and artists saw the potential to create amazing things with fewer resources and more creative mathematical approaches. This efficient approach is still used in modern game development, special effects, and even scientific visualization today, proving its long-term value.

"The beauty of signed distance functions is their simplicity. You can define almost any shape with just a few lines of math, and then combine them in endless ways."

This specific example helped popularize the idea that complex visual results don't always require massive codebases or expensive software. Sometimes, a brilliant idea expressed simply can change how we think about a problem, opening doors to new methods and tools. It showed that understanding the underlying math can lead to incredibly powerful and compact solutions.

More Than

Just a Donut: A Lesson in Simplicity

The story of the 46-line Python donut is a powerful reminder that innovation often comes in small packages. It proved that complex visual results don't always require massive codebases. Sometimes, a brilliant idea expressed simply can change how we approach an entire field.

It highlighted the beauty of mathematics in computer science, showing how abstract concepts can lead to concrete, stunning visuals. It encouraged people to look for elegant solutions rather than complicated ones, proving that simplicity can be the ultimate sophistication. This little script became a quiet legend, teaching many that the most profound lessons often come from the smallest examples.

This viral moment, though perhaps forgotten by some, continues to influence how we approach graphics and programming. It remains a powerful example of what a few well-chosen lines of code can achieve, inspiring a generation to explore the creative possibilities of mathematical algorithms.

How does this make you feel?

Comments

0/2000

Loading comments...