I replied without looking closely at your code, only the thread title (“Assign colors to tree branches”) but when I did look later, I was confused by it. What I expected was similar to the circled text panel on the right - colors by branch. But neither of your Python outputs produce that pattern. If I wanted to use an explicit list of colors as you did, I would connect color Swatch components to Entwine, one per branch, and be done with it, as in the purple ‘Color list’ group below.
So I created this model to illustrate the difference between ColorB (by branch), ColorJ (by item) and ‘Color list’ (Entwine). I created a grid pattern of points because it makes it easier to see how ColorB and ColorJ work when their ‘J’ (Jitter) inputs are set to zero (no jitter).
Two Value List components (blue groups) allow you to choose which color method is used and a ‘SRC’ (source) geometry, either the grid of points or your curves.
I am surprised to discover two things:
ColorJ has a bug that causes it to show nothing (!!) when there is only one item in a branch. I’m stunned by this (I’ve been using it for a long time) but understand it and will fix it somehow.
‘Color list’ behaves as expected with the point grid: branch 0 is white, branch 1 is red, branch 2 is blue and all remaining branches are yellow because I have more branches than colors. I am baffled, however, by what I see when I use your curves: branch 0 is white, branch 1 is red and branch 2 is yellow, not blue!!?? Why is blue missing? Can anyone explain this mystery to me?