2D Metaballs Demo using Marching Squares
2022 April 04

Metaballs are organic looking blob like balls that merge and split apart based on their distances from each other. They can be defined as a single function or a summation of functions across the x and y plane. By computing the contours, a very cool picture can be produced in real time as shown below. However, computing the entirety of the function plane to a high degree of precision is very expensive. To make it less expensive and produce a good high quality contour marching squares can be used. It samples 4 points of a function and interpolates where a threshold value occurs to draw the outline. I was inspired by Reducible’s video on how computers can draw weird shapes.

The awesome thing about marching squares is that it takes advantage of some bit masking to be really fast. It’s also a really good divide and conquer algorithm, because it doesn’t depending on the results of the neighbors. It has lots of applications in graphics, and GIS. It offers some nice properties for creating contour maps, depending on the threshold value.

I hope you enjoy the show below. Feel free to refresh the page to see different initial configurations. The balls do not self interfere, but the starting conditions determine it all. The numerical simulation might not be perfect, but I think that makes it cooler. Everything is computed in real time.

As always the source code is embedded into the post (Right click -> View Source).


Remember you can also subscribe using RSS at the top of the page!

Share this on → Mastodon Twitter LinkedIn Reddit

A selected list of related posts that you might enjoy:

*****
Written by Henry J Schmale on 2022 April 04
Hit Counter