# Attraction and Angle_Field Nodes

As part of my recent engagement with Jussi, I am deprecating my old attractor node and replacing it with two NEW nodes:

- attraction
- angle_field

My attractor was included way back in the first release of my node library. It's a powerful and potentially useful node, but I confess to rarely using it. Jussi's prompt about signed distance functions reawakened my interest and motivated me to make it more efficient. The key part of doing this was to break it into two separate nodes.

Attractor was slow because it tried to do two different things at once: find distances and find angles. It did the work for both regardless of which option you chose. Now, by choosing a separate node for each function, both work faster.

Attraction computes normalized minimum distances from points to a shape. It takes six parameters:

**Particles**. A list of points**Attractor**. A shape. Shapes with contours (holes), open paths, and grouped geometries are allowed.**Mode**. Attract or Repel. In Attract mode, points far from a shape boundary will approach 0 and points near it will approach 1. In Repel mode the reverse is true.**Sample Length**. The resolution used when resampling the Attractor shape to quantify its boundary. The default value of 10 (one point every 10 pixels along the edge of the shape) works well in most situations. Changing this value can sometimes produce some unusual results.**Sharpen**. Change the range used to determine normalization; values can range from -99 to +99. The best way to understand this parameter is to use the distances to set the size of dots for each particle and change it to see what happens. Increasing the Sharpen value from its default of 0 tends to bring the shape into sharper focus. Giving Sharpen a negative value muddies the image, ultimately reducing it to a featureless soup.**Multiplier**. A constant value that multiplies the normalized (0 to 1) distance values. This is handy when using the distances to determine the diameter of dots for each particle. Increasing dot sizes until the biggest ones start to collide makes for a bolder image.

Angle_field computes the direction from points to the nearest part of a shape. I takes four parameters:

**Particles**. A list of points**Attractor**. A shape. Shapes with contours (holes), open paths, and grouped geometries are allowed.**Mode**. Attract or Repel. In Attract mode, points will point toward the nearest shape boundary; In Repel mode they will point away.**Sample Length**. The resolution used when resampling the Attractor shape to quantify its boundary. The default value of 10 (one point every 10 pixels along the edge of the shape) works well in most situations. Changing this value can sometimes produce some unusual results.

When determining angles, the angle_field node finds the three nearest points and then takes a weighted average (based on relative distance) of those three directions to determine the overall direction. Finding these angles takes a little longer than it takes to find only the distances.

The attached demo (see screenshot) shows both nodes applied to the same shape and particle field. For a shape I use a large lower case a (I use TimesNewRomanBold, but you can change it to any other font if you don't have that one). For particles I generate a square grid of 40 x 40 points (1600 altogether) spread evenly across a 1000 x 1000 canvas.

At a 40 x 40 resolution, My MacBook Pro renders both the dots and arrows in about two seconds; the dots come almost instantly, the arrows take noticeably longer. If you raise the resolution above 40 you will get a more detailed output, but it will take longer to render.

It's fun to render just the ellipse2 node and try changing the Sample Length, Sharpen, and Multiplier parameters to see what happens. You can also try different shapes.

In the 3.4 release of my library, attractor will be removed and replaced by these two nodes. Enjoy!

- attraction_screenshot.png 1.33 MB
- attraction_demo.ndbx.zip 6.13 KB

# 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