поговоримо про більш складні маніпуляції зі списками. Наприклад нод Shift List
Ось так виглядає результат його роботи і зараз трошки детальніше його розберемо.
It is very important to consider the behavior of nodes with different lengths of lists. That is, in all previous examples with points and radii, the length of the lists was the same (the number of elements in the list).
Now let's consider what will happen if we have one point and 3 radii. In this case, we still get 3 circles with different radii but with the same center.
Let's try the opposite - 3 points and one radius (we have already done this at the beginning of this section). And once again, we see that the result is 3 circles with different centers but the same radius.
Now let's try 2 points and 4 radii. In this case, we get the following result: one circle on one point and three circles on the second point. This behavior may seem strange to you, but knowing its rule is enough to understand everything.
The first thing we always need to remember is that data lists have a clear sequence, so when we create any list, we must take this into account. After all, it is in that order that the main rule of working with lists in gh will be applied.
<aside> 📌 If we have several lists of different lengths, for example:
points - [ p1, p2 ]
and radii - [ r1, r2, r3, r4 ]
then when we connect these lists to the Circle
node, the following happens:
1/ The first point p1
is used to create a circle with a radius of r1
.
2/ The second point p2
is used to create a circle with a radius of r2
.
3/ We don't have a third point, but we have a radius, so we take the last point p2
from the list and apply the radius r3
to it.
4/ We do the same with the fourth radius r4
and use the last point from the list p2
as the position.
</aside>
Remember the example with the balls at the beginning of the section on lists, it actually illustrates the basic principle of how gh works with data.