# Grids?

There’s something about grids in Nodebox that I’m not quite understanding. I have set up a Nodebox file where I am plotting 150x150 squares onto a grid. I have set up my grid with 10 columns and 10 rows, with the width and height set to 1500 each. I thought this would be the correct width and height to use to accommodate 10 squares of 150x150, but the squares have big spaces in between them. I changed the width and height of the grid to 1350 each, and now my squares look like they sit flush next to each other.

It’s strange though, because when I change my columns and rows to 5 each, I have to change the width and height to 1200 each, where I thought that the width and height should’ve been 750 (150x5) each. How does one go about calculating the correct width and height for the squares to sit flush next to each other in this scenario?

# 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

johnon 11 Nov, 2019 11:28 PMHello Ernstnext,

This is a problem we've all struggled with.

Everything in Nodebox is positioned from the center. So when you use a grid node to create 100 (10 x 10) rectangle positions, each of those points is in the center of its rectangle. The width of a grid is the distance from the leftmost

centerpointto the rightmostcenterpoint- not the distance between the left and right edges.The difference is half a rectangle width on the left and another half a rectangle width on the right. So you have to subtract 1 from the number of columns and 1 from the number of rows. Here is the formula:

In your initial case, both gridWidth and gridHeight = 150 * 9 = 1350.

If you have only 5 columns and 5 rows, grid width and height is 150 * 4 = 600. I don't understand why you said it has to be 1200, unless you also changed the width and height of your rectangles (to 300 x 300).

If you want to avoid the math, you can use my grid_plus node instead of the standard grid node. Grid_plus is one of 57 nodes available for free here:

http://support.nodebox.net/discussions/show-your-work/336-cartan-no...

Just download the library, open it, and copy-paste the grid_plus node into your project.

Grid_plus lets you enter the desired cell width and cell height - in your case 150 x 150. Then change your rows and columns as you wish and grid_plus will do the math for you. It allows you to limit the total number of points (for cases where you need partial rows) and lets you order the points from right to left or bottom to top. I've found it very useful over the years.

Please let me know if that answered your question. And please keep asking questions - it helps all of us learn.

John

2 Posted by

ernstnexton 12 Nov, 2019 06:05 AMJohn, thank you so much for your wonderful, in-depth answer to my question! And thank you for the additional node library, I didn't know this existed (I'm fairly new to using Nodebox), and can't wait to get stuck into the additional nodes!