Recursion or quadtree pattern based on image sampler


I am interested in generating a pattern tile based on the UV map of an “Image Sampler”, similar to this example

As I understand it, one would need create a loop that analyzes, based on the UV map of an “Image Sampler”, the average value (from 0 to 1) inside the area of a surface, then divide that surface if the value meets a certain condition (for instance higher than 0.1), the next loop cycle it should analyze all the surfaces created last cycle and divide again based on the previous condition but with a slight modification (this time values higher than 0.2) repeating this an “X” number of cycles.

Maybe there I am completely wrong and the way to achieve this is completely different. After all, tutorials about Anemone seem to be few and far between, so far, I haven’t been able to find any that relates the topic of Image sampling to loops and I don’t know how to translate these conditions to an actual algorithm, any help would be appreciated.

This are a few posts with similar ideas.

And this one récent

1 Like

Why not using the scripts proposed in the references ?

hello Laurent,

unfortunately, K-Ds example doesn’t seem to work in my pc, the code isn’t opening properly because it seems to be missing some connections, probably it was done with a newer version of grasshopper. Your code is amazing but it looks too complicated for my level of expertise, I was trying to find some tutorial or simpler code that I could apply.

I tired developing my own but it isn’t giving me the results I expected, you can take a look at it and maybe make some comments/modifications

It also looks like QuadTrees are a more efficient way of getting this sort of result, but I don’t know how to use them in grasshopper.

I didn’t look closely on you code.
If my script is too complex it is because it is using just grasshopper components. The big trick is to measure the deviation (standard deviation or max deviation) of color/brightness or whatever in each cell and then subdivide or not it.
As it is recursion the best is to code it (Python or C#).

Here another nice implementation.


Yeah, I figured the trick is in handling how you (measure the deviation) as you say and that’s the part that gets me, do you think you could isolate the part you use to measure the deviation within your file. Unfortunately, I am just getting started with coding so I wanted to understand how this works just with function.

The Link you send was amazing, definitely going to check it out in detail

The upper parts of the script are the measurements

This part before the image sampler is putting random points on rectangles

To explore a script use the
So clicking on a component you will see the geometry. It it is not a geometry, put a panel at the end.
So explore, see the transformations … It is long but in order to understand you’ll have to do it.
Algorithmic thinking takes time or you are a genius .

it is taken from here