List Position
Is there any way to give items of a list a behaviour, that is dependent on the items position in a list in nodeBox3 ? What I would like to do is to move shapes in dependence of their list position to different points.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Frederik De Ble... on 17 Dec, 2016 08:03 AM
Sure, but it might work a bit differently from how you think it would work. You could create a second range node that runs indices from 0 to the
count
of items in the list. Then you could feed in that "parallel" list to a new node (ie. rotate, translate) and let list matching combine the shapes and values for you.2 Posted by ppape on 17 Dec, 2016 05:02 PM
Thank you very much Frederik for your fast answer. I tried something like your example but then recognized, that my problem is far more complicated then I wrote in my question. So my question was wrong.
Actually I have to consider not only the position of one item in a list, but also for each previous item and their properties.
What I finally want to do is to arrange (in dependency of written letters) 4 different objects of two different widths and hights in columns so that they finally fill a column. Each of the objects represents one version of a letter. So for every "A" for example there are four different versions The first objects is random and the following object has to fill the "line" if hoizontal space is left and at the same time look for the vertical length of the previous object. So I think I have to work with different lists, but as I have to select objects in dependence of previous objects I can't find a way to go back in a list or save the current version of the arrangement before positioning the next object.
Sounds as complicated as it seems to me. I'm sorry. I attach a picture of two arrangements to show, what I want to accomplish.
I am very thankfull for any help.
3 Posted by matveev64 on 18 Dec, 2016 03:31 PM
Experiment
4 Posted by ppape on 18 Dec, 2016 06:28 PM
Thank you very much Frederik for your help. That showed me, that my problem is far more complex. then I originally thought. So my question was wrong.
What I have to do ist not only to look for an items position in a list, but to consider also the previoous items in that list. So my question is how can I look back in a list.
I want to place objects of different widths and hights in "columns". These columns have a fixed width so the objects have to consider, the width of objects in the same line, to not run out of that width.
I add two pictures of these filled columns.
What I can not find out is, how to move the objects depending on the previous objects. I think that I need to work with different lists, but as I do not know the order of the objects before, I somehow have to look backwards. But I do not know how.
Thank you for any help.
Support Staff 5 Posted by john on 19 Dec, 2016 01:21 AM
Hi Phillip,
I have created stacks of multi-sized boxes in NodeBox before. There is usually a way of doing almost anything if you think about it in the right way.
What are the constraints on your boxes? What is the minimum and maximum height and width? Are they integer values or completely unpredictable? Are they arranged in different columns according to some other factor (e.g. date), or are you simply filling the space any way you can? Does it matter what order the boxes are stacked?
Depending on how you answer these questions, there may be some way of calculating an acceptable arrangement ahead of time. One thing you can do is sort your list by width so that all the widest boxes are dealt with first.
In one project I did, there were three possible sizes of square box, 4x4, 2x2, and 1x1, so that I could always fill the column width exactly. More complex patterns could also be handled if you have can choose your possible sizes carefully.
This problem is similar to the task of creating a treemap, a visualization of a hierarchical structure as boxes within boxes that fill a rectangular space. I have done this before in NodeBox as well.
If you tell me a bit more about your project I may be able to help.
Thanks,
John
6 Posted by ppape on 19 Dec, 2016 02:33 AM
Hi John,
the constrains seemed easy to me in the beginning. The boxes are similar to your example: The can be 1x1, 1x2, 2x1 and 2x2. The height of the columns will not be predectiable, because a user should later type a text and depending on that text the column shall be created. For each letter there are four different kinds of tiles. And the programm should pick the right version of the tile to fill the column.
Is that understandable? Hope so. Thank you for your help.
Support Staff 7 Posted by john on 19 Dec, 2016 03:12 AM
Do you care what order the boxes are stacked?
If not, you could put the 2x2 boxes at the bottom, then add the wide 2x1 boxes, then the tall 1x2 boxes, then fill the remaining space with 1x1 boxes. You can filter the list for each type, construct partial stacks for each type, then put the partial stacks back together. The only tricky but would be ensuring the final layer of 1x1 boxes fill a possible 1x2 gap in the topmost row before continuing upwards.
If the boxes have to strictly follow the order of the letters in the text, I don't see how you could avoid cases in which some rows were 3 units wide.
Let me know if you need more help. If it is permissible to arrange the stack with biggest blocks at the bottom, describe how the four types are derived and I can write some example code for you.
John
8 Posted by ppape on 19 Dec, 2016 08:09 AM
For each written letter I will have four different versions of tiles later.
The program should be able to choose the next tile by chance as long as it fits in the row.
I wonder wether I can save the status of the pervious objects in a variable. So that depending on that variable I can select the group of shapes from which to choose by chance. But I don't see a way how to overwrite variables in nodebox yet.
9 Posted by ppape on 19 Dec, 2016 10:24 AM
The attached nodebox-file shows how I am trying to campare list items (in this case a binary list with the same items (just the first item removed). Is this the best way to do something like that?
But how then can I switch objects on and off and move objects depending on the resulting binary list? I tried it with the switch-Node but didn't succeed.
Support Staff 10 Posted by john on 19 Dec, 2016 10:56 AM
I couldn't quite tell what you were trying to do with that example. What you did was:
- make list A of random 1s and 0s
- make list B of all but first value of A followed by second value of A
- find all positions where both A and B = 1
Is that what you intended? Even if it was, I'm not sure where you would go from there.
Maybe you need a different approach, one that does not require comparing or moving anything. Since the tiles are chosen randomly, why not just create a list of all possible legal rows of height 1 or 2 (I count six possibilities), choose these legal rows at random, stack them up, and, if you wind up with 1 or 2 more tiles than you need, slice off the length of your original string.
Would that work? It's past my bedtime, but I might take a quick stab at it to show you what I mean.
Support Staff 11 Posted by john on 19 Dec, 2016 12:17 PM
Phillip,
Here is some example code and a screenshot of the approach I suggested in my last note.
For each stack I create a set of randomly chosen legal rows:
- two 1x1s
- a 2x1
- two 1x1s (vertical) plus a 1x2
- a 1x2 plus two 1x1s (vertical)
- two 1x2s
- a 2x2
I stack these rows vertically to create a stack guaranteed to be taller than we need. I then ungroup them into a set of boxes ordered left to right from the bottom up and slice a subset equal to the total number of letters in the text string. I superimpose the letters inside each box to produce the final stack.
My stack subnetwork takes a text string and a seed for the random number generator. To illustrate the variations I feed it four different seeds and draw the resulting stacks side by side.
Would this approach serve your purpose?
John