The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.

NodeBox 3From the old forum

color number of objects in grid.

4 replies Last reply

  1. Hi,
    I'm wondering if there is any way to color a certain number of objects placed in a grid.
    E.g. If I create a grid of 100 rectangles (10x10 grid) can I make it so 63 of them are one color and the rest stay black?
    How would I go about doing this if possible?

    Any help will be much appreciated thanks.

    DN3

    Copy link
  2. One simple way to do this is to slice your rectangles into two groups, color each group, then recombine.

    1. Attach grid node to rect node to create 100 rectangles
    2. Attach a slice node with start=0 and size=63 to your rect node
    3. Duplicate (copy/paste) that slice node and set invert to true. Both slices now attached to rect.
    4. Add colorize nodes to each slice (e.g. one blue, the other black)
    5. Combine them with a combine node.

    Screenshot and sample attached. Happy NodeBoxing!

    John

    Copy link
  3. Thanks so much guys. The slice node was the key I was missing. I had been looking for something with that functionality but somehow missed it.

    Copy link
  4. Great solution from John again. Another way (there are many ways of doing this depending on your project goal), is to calculate the proportion of colors you need and then generate a list of colors to colorize the rectangles. It requires a few more nodes but the advantage is that if the proportion changes you do not have to change the numbers in two nodes, it is controlled by one number. Clever construction of your network allows for a network that can adapt to any number (or even any size of grid) that gets in. In particular handy for generative systems or data visualisation. The network in the sample I attach is not controlling if you go over 100 or under 0. The squares will be then all black in the former or all blue in the latter case. If a decimal number is put in the system automatically rounds the numbers, because the repeat node requires an integer.

    good luck,

    Lucas

    Copy link

Know something that helps?

Sign in with your email address to reply. No password needed.

Sign in to reply