After reading the post from @lylejk : https://discuss.pixls.us/t/variable-density-hilbert-curve
(and after finishing up the few things I had to do before diving into this), I thought it would be fun to try implementing a locally variable-density Hilbert curve effect.
And to give myself a little motivation, what could be better than doing this as part of a new episode of G’MIC Adventure? ![]()
The goal here is then to write a G’MIC command that is able to reproduce an input image with a single curve that looks like a Hilbert curve, so something like this:
(image borrowed from the original post from @lylejk ).
That’s what I’m going to try to do here!
And since I’m naturally curious and enjoy learning new things, I’m going to avoid asking an LLM to code this for me from scratch
The bad news: I have absolutely no certainty that I’ll succeed in this challenge, and it’s entirely possible that I won’t. But that’s exactly what makes it so interesting, because I’ll be able to describe the different stages of my thought process as I try to reach that result. It’s a bit like an LLM’s “chain of thought,” but much slower ![]()
Image analysis:
Looking at the goal image, I understand I will have to construct a single Hilbert Curve in a way that allows me to locally applies a different “subdivision deep” for the curve construction. So first, I need to understand how to construct the Hilbert curve, by iterating subdivisions and transformations.
G’MIC already has a command shape_hilbert that draws a Hilbert Curve, but it uses some fancy math tricks to get the parameterization of the curve without having to deal with explicit subdivisions.
So a good idea is to first try to re-implement a command that draws the standard Hilbert curve, but using an iterative approach.
Understanding how the Hilbert Curve can be constructed iteratively:
Looking at the wikipedia page: Hilbert curve - Wikipedia
I see we can start from a ‘U’-shaped curve, and apply 4 different geometric transformations on its vertices, to get a new “subdivided” curve that is the level-1 of recursion for the Hilbert Curve construction.
OK, OK, let’s try this!
(to be continued…)













