color number of objects in grid.

DesignerN3's Avatar

DesignerN3

01 Sep, 2017 11:08 AM

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

  1. 1 Posted by andy.treichler on 01 Sep, 2017 04:10 PM

    andy.treichler's Avatar

    Dear DB3

    I think "comparison example in math tutorial" could be the solution to your question.

    http://support.nodebox.net/discussions/nodebox-2-3/181-comparison-example-in-math-tutorial

    Rgs
    Andy

  2. Support Staff 2 Posted by john on 01 Sep, 2017 05:07 PM

    john's Avatar

    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

  3. 3 Posted by DesignerN3 on 01 Sep, 2017 09:39 PM

    DesignerN3's Avatar

    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.

  4. Support Staff 4 Posted by lucasnijs on 04 Sep, 2017 08:48 AM

    lucasnijs's Avatar

    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

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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

Recent Discussions

26 Jan, 2025 02:09 AM
24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM
21 Jan, 2025 09:41 AM

 

21 Jan, 2025 09:36 AM
21 Jan, 2025 02:00 AM
16 Jan, 2025 08:30 PM
15 Jan, 2025 06:37 AM
04 Jan, 2025 04:09 AM
03 Jan, 2025 05:32 PM