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.
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.
After grabbing those pixels, we go ahead and break down the colors to use in Dynamo!
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).
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.
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.
When we are all done with the geometry we can now override the cubes based on the colors from the image.
And here it is in action using the direct movement of a point in Dynamo.
If you have enjoyed this, please comment/share!
Download Script Here: Opposites Attract Dynamo Script