Not that kind of attraction! I’m talking point attraction in Dynamo of course.
Here is what we are going to make when all is said and done.
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_528e2831a1114dfab953d0546cc629bc~mv2.png/v1/fill/w_980,h_384,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/1865b4_528e2831a1114dfab953d0546cc629bc~mv2.png)
Now we’ll break it down.
First, we need to find a source image and break it down a bit. Luckily, I found a perfectly square image which made life easier. Also, for some reason it makes life easier to rotate the image like shown below. In this case, we will go ahead and grab an even number of pixels from the image’s height and width.
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_ec2871f0bd284696aa021417552c4ea2~mv2.png/v1/fill/w_774,h_646,al_c,q_90,enc_auto/1865b4_ec2871f0bd284696aa021417552c4ea2~mv2.png)
After grabbing those pixels, we go ahead and break down the colors to use in Dynamo!
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_5b4770a10f3c4ca2ae5a3d71df8dd021~mv2.png/v1/fill/w_517,h_216,al_c,q_85,enc_auto/1865b4_5b4770a10f3c4ca2ae5a3d71df8dd021~mv2.png)
Next, we need to generate a surface to work with to process the “directions” from the image. For this example, I used a line to extrude a surface that is the same dimensions as my image.
I also went ahead and placed points on this surface at the same spacing and logic as my image from before, (25x25).
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_94950fab2fc149bc984cd4c46e6896b6~mv2.png/v1/fill/w_920,h_353,al_c,q_85,enc_auto/1865b4_94950fab2fc149bc984cd4c46e6896b6~mv2.png)
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_02ee0a7abfe24e90bd5384705838003a~mv2.png/v1/fill/w_434,h_405,al_c,q_85,enc_auto/1865b4_02ee0a7abfe24e90bd5384705838003a~mv2.png)
Next, we need to generate something called an attractor point. This means we measure distance between one item, (in our case a point), and several other items, (in our case 625 other points). The way this is achieved is through a node called, “Geometry.DistanceTo”. It is important to keep in mind that this node will return the literal length from the attractor point to the other points, we’ll fix that next.
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_8c4de587637b4324b2125ba199d1cdc8~mv2.png/v1/fill/w_688,h_189,al_c,q_85,enc_auto/1865b4_8c4de587637b4324b2125ba199d1cdc8~mv2.png)
To fix this situation, we will use something called “Math.RemapRange”. This beautiful node will redefine all the numbers in a list, based on a minimum and maximum value. Once again, this means Dynamo is doing math on 625 numbers way quicker than I can.
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_d09b8e8725064f1eb4244de010bab069~mv2.png/v1/fill/w_505,h_341,al_c,q_85,enc_auto/1865b4_d09b8e8725064f1eb4244de010bab069~mv2.png)
When we are all done with the geometry we can now override the cubes based on the colors from the image.
![Dynamo Attractor](https://static.wixstatic.com/media/1865b4_d7c75477f86947b5979739cf0a145be0~mv2.png/v1/fill/w_419,h_255,al_c,q_85,enc_auto/1865b4_d7c75477f86947b5979739cf0a145be0~mv2.png)
And here it is in action using the direct movement of a point in Dynamo.
![Dynamo Attractor gif](https://static.wixstatic.com/media/1865b4_1eecec102719495d82ea1c7065d3e6b3~mv2.gif/v1/fill/w_980,h_521,al_c,usm_0.66_1.00_0.01,pstr/1865b4_1eecec102719495d82ea1c7065d3e6b3~mv2.gif)
If you have enjoyed this, please comment/share! Download Script Here: Opposites Attract Dynamo Script