# Using arrays to create a node and edge connector

**URL:** <https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464>\
**Category:** Coding Questions\
**Created:** [October 6, 2019, 12:20pm UTC](https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464 "2019-10-06T12:20:51Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 3, 2019, 3:05am UTC](https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464/20 "2019-11-03T03:05:24Z")

</div>

> [@johnsmith17](#):
>
> make each node connect to the nearest grid intersection

Do you mean draw a line from each node to the nearest intersection? Or do you want to “snap” the points to the nearest grid intersection?

If you are trying to snap points to a regular grid, you can use snap-closest based on modulo (%) – see this example:

> [@How to snap mouse to a shape/coordinate?](https://discourse.processing.org/t/how-to-snap-mouse-to-a-shape-coordinate/13414/9):
>
> The simplest way to snap in 2D is %. Define your grid step, then subtract the modulo of that from your current location to snap, no modulo for free motion. int gstep = 10; void draw(){ background(128); if (keyPressed){ ellipse(mouseX, mouseY, 10, 10); } else { ellipse(mouseX - mouseX%gstep, mouseY - mouseY%gstep, 10, 10); // snap } lines(); } void lines(){ for(int x=0; x\<=width; x+=gstep) line(x,0,x,width); for(int y=0; y\<=height; y+=gstep) line(0,y,height,y); } This as…

---

_[View the full topic](https://discourse.processing.org/t/using-arrays-to-create-a-node-and-edge-connector/14464)._
