It’s for generating 2D branching patterns, with no looping - just simple maths, repeating data and a clever bit mask method to untangle overlapping lines. Everything fits in a 1x1 square (or adjust X/Y to suit) ready for sporphing or whatever. Doesn’t even have to be a grid really, so long as you present a list of coordinates that make sense read from left to right.
The branching controls are a sequence of numbers, which say how many branches there are at that level of the tree. So 1,1,2 means
Start with 1 root
Add 1 trunk
Split in 2
= 1x1x2 leaves
Planned for v2: Surfaces spanning between adjacent branches (with optional “wrapping” parts to fill up to the sides when Spoprhing onto surfaces of revolution or similar topology).
You’re a wizard, Volker Very nice use of Domains in the setup phase.
My first version also operated on line segments instead of vertices, but doing the valley-ridge part worked out easier if I hung on to the vertex positions so I could keep the Ridge connected to the “fork”.
“Surely there’s an easier way of doing this” I would say to myself doing (Graft, Repeat Data, Trim Tree) over and over again. Yes, yes there is, and it’s called Stack
I’m still proud of my “bit mask” method for assembling the non-overlapping polylines, although I’m sure that’s also possible to simplify!
Now, for the Hard Mode challenge
Can this be done with arbitrary numbers of nodes at each level?
The current implementation always multiplies the previous node count by some integer, but what happens if you allow fractional increases? So eg. instead of A: 1 x 2 x 2 x 3 to make a tree with 2, then 4, then 12 nodes, is there a deterministic way of making B: 1 x 2 x 1.5 x 4 to make a tree with 2, then 3, then 12 nodes? Or to go even further, C: a list of the number of nodes at each level?
I think C is impossible without loops. For example, in the above diagram, how do you decide what is the parent node of the 4th leaf? I used up a lot of ink and brain cells and couldn’t find a way.
I don’t know about arbitrary, but perhaps by other rules. There are entire production grammars out there, like L-systems that define different branch generation algorithms. Maybe some of the more mathematically minded individuals like @laurent_delrieu could help you out here.
Some results from a search for "L-system" on the forum: