tag:support.nodebox.net,2012-11-01:/discussions/nodebox-2-3/5874-list-positionNodeBox: Discussion 2018-12-30T18:24:57Ztag:support.nodebox.net,2012-11-01:Comment/415661542016-12-17T07:56:31Z2018-12-30T18:24:57ZList Position<div><p>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.</p></div>ppapetag:support.nodebox.net,2012-11-01:Comment/415661542016-12-17T08:03:20Z2016-12-17T08:03:20ZList Position<div><p>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 <code>count</code> 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.</p></div>Frederik De Blesertag:support.nodebox.net,2012-11-01:Comment/415661542016-12-17T17:02:59Z2018-12-30T18:24:57ZList Position<div><p>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.</p>
<p>Actually I have to consider not only the position of one item in a list, but also for each previous item and their properties.</p>
<p>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.</p>
<p>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.</p>
<p>I am very thankfull for any help.</p></div>ppapetag:support.nodebox.net,2012-11-01:Comment/415661542016-12-18T15:31:02Z2016-12-18T15:31:03ZList Position<div><p>Experiment</p></div>matveev64tag:support.nodebox.net,2012-11-01:Comment/415661542016-12-18T18:28:39Z2018-12-30T18:24:57ZList Position<div><p>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.</p>
<p>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.</p>
<p>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.</p>
<p>I add two pictures of these filled columns.</p>
<p>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.</p>
<p>Thank you for any help.</p></div>ppapetag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T01:21:01Z2016-12-19T01:21:01ZList Position<div><p>Hi Phillip,</p>
<p>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.</p>
<p>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?</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>If you tell me a bit more about your project I may be able to
help.</p>
<p>Thanks,</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T02:33:32Z2018-12-30T18:24:57ZList Position<div><p>Hi John,</p>
<p>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.</p>
<p>Is that understandable? Hope so. Thank you for your help.</p></div>ppapetag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T03:12:44Z2016-12-19T03:12:44ZList Position<div><p>Do you care what order the boxes are stacked?</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T08:09:45Z2018-12-30T18:24:57ZList Position<div><p>For each written letter I will have four different versions of tiles later.<br>
The program should be able to choose the next tile by chance as long as it fits in the row.</p>
<p>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.</p></div>ppapetag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T10:24:06Z2018-12-30T18:24:57ZList Position<div><p>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?</p>
<p>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.</p></div>ppapetag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T10:56:20Z2016-12-19T10:56:20ZList Position<div><p>I couldn't quite tell what you were trying to do with that
example. What you did was:</p>
<ul>
<li>make list A of random 1s and 0s</li>
<li>make list B of all but first value of A followed by second
value of A</li>
<li>find all positions where both A and B = 1</li>
</ul>
<p>Is that what you intended? Even if it was, I'm not sure where
you would go from there.</p>
<p>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.</p>
<p>Would that work? It's past my bedtime, but I might take a quick
stab at it to show you what I mean.</p></div>johntag:support.nodebox.net,2012-11-01:Comment/415661542016-12-19T12:17:50Z2016-12-19T12:17:50ZList Position<div><p>Phillip,</p>
<p>Here is some example code and a screenshot of the approach I
suggested in my last note.</p>
<p>For each stack I create a set of randomly chosen legal rows:</p>
<ul>
<li>two 1x1s</li>
<li>a 2x1</li>
<li>two 1x1s (vertical) plus a 1x2</li>
<li>a 1x2 plus two 1x1s (vertical)</li>
<li>two 1x2s</li>
<li>a 2x2</li>
</ul>
<p>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.</p>
<p>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.</p>
<p>Would this approach serve your purpose?</p>
<p>John</p></div>john