# How to achieve this spline and particle effect

does someone have any idea of how to achieve the following effect in Blender? the source of this file is http://www.rawandrendered.com/camp-2016-titles

I tried to apply curves to a deformed surface, but that was a bad idea. the distribution of the curves looks like a magic texture, but working with such didn't work either.

Is this something that can be done with animation nodes? Or with a particle system?

EDIT - further Question

Hi Omar, thank you very much for help. I have deep respect for your knowledge in both math and programming. I hope the edit of this post is the right place to ask further questions.

I tried to follow your steps, but until now, i ran into two troubles. Please refer to this image: As you mentioned, for the sake of using AN 2.0, i replaced the vector noise node with an expression node. But how can i combine the expression node with the group output? The Problem occurs at the point marked with "A" in the image above. Second, at the point marked with "B", i did not manage to get a loop output. Would you be so kind to explain how this can be achieved?

Thank you very much for your help!

*EDIT Related question: Trace visualisation in 3D - how to wrap curves onto a 3D mesh

## Animation Nodes Version

Animation Nodes v2.1 includes a very fast and efficient noise functions and so I will be using this version in my answer. However, I also provided an alternative using older versions of Animation Nodes, though it is not as efficient as I stated above.

## The Theory

The image you posted above is a trace visualization for what is known as a divergence free vector field. To demonstrate what that mean, consider particles that move along the lines you see above (The field represents their velocity), if the field is indeed divergence free, those particles will never collide. That's what gives this visualizations their beauty, the lines never intersects.

Mathematically, a vector field $F$ is divergence free if $\nabla \cdot F = 0$. In the the paper "Curl-Noise for Procedural Fluid Flow", Robert Bridson described a method to generate those divergence free vector field from simple Perlin noise. He proposed computing the curl of a vector field composed of Perlin noise to get a divergence free vector field, it is a known identity that the curl of any field is automatically divergence free. In particular, he proposed an equation to compute the "2D curl" of simple perlin scalar fields which is exactly what we want to get the visualization above. The equation he proposed is:

$$\vec{v}(x, y) = \left( \frac{\partial \Psi}{\partial y}, -\frac{\partial \Psi}{\partial x} \right)$$

Where Psi is the perlin noise field. Don't worry if you don't understand the equation, I will walk you through it. It can be noted that the computed vector is just the gradient rotated by 90 degrees.

Now that we know how to compute the the vector field, we can generate the splines by tracing the vector field using what is known as Euler's Integration, if you don't understand this method, don't worry, you will get it through our implementation.

## Implementation

To compute the partial derivatives in the equation above, we are going to use what is known as the Central finite Difference method. I will leave you to study that for study and practice and I will just do the implementation directly: We just take the input vector, move it a bit to the right and a bit to the left, evaluate the noise at the new location then take the difference. Same for the $y$ axis. When we make the amplitude the reciprocal of the epsilon (the bit we moved the vector by), we won't have to divide by it.

Next we will make a loop that computes the points of the splines using Euler's method: We start at some vector, compute the curl using the equation above by using the group we did above. Then we move in the direction of that curl and reassign the initial location to be the new location.

Next we will make a loop that generates the splines for multiple points: And by viewing the output splines: We get something similar to what you want to achieve. Now by adding the value of the perlin noise as the z location of the spline points, we get exactly the result you are looking for: It should be noted that there is much more efficient way to make this, but this is the easiest way, if you want to know the other way, let me know.

This should be it for splines. I think particles are not hard to create and you should create them as a practice. Let me know if you need elaboration or help on any part.

## Edit 1

### Using Older Versions Of Animation Nodes:

The only node that is not available in older version is the Vector Noise node. The mathutils python module provide an alternative, but it is much slower and doesn't give a lot of control, and that's why I didn't want to use it.

All you have to do is replace the Vector Noise node with an expression node that takes a vector list and returns a float list with an expression:

[mathutils.noise.noise(x) for x in vectors]


Making sure you have imported mathutils and named the vector list vectors: There are also other types of noise that you can experiment with, you can find the API here.

## Deform It Along A Grid

Notice that in the Splines loop, we set the z location to be the value of the noise. Instead, you can just set it to anything else. In your case, if you want to deform it along a grid, you can use a BVH tree: And yes, this works with lattice deformed grids as you may see in my example above.

## Edit 2

### What To Put At A

The hidden nodes are Get List Element Nodes with indices, 0,1,2,3 from top to bottom.

### How To Add A Generator

In the Loop Input node at the far left, there is a plus button called new Generator Output, search for vectors after pressing it.

### File for v2.0 to study ## Edit 3

To assign different colors to each spline, you should separate splines to different objects (This is your best option), this can be done using such node tree: Then assign the material to all the generated splines by adding it to a single one, selecting all and then Ctrl+L >> material. For this material, we will use such a node tree: Which will assign a random color to each spline.

• Hi Omar, thank you very much for your detailed answer. Even tough i did not get all the math, i am impressed with the result. Unfortunately, the problem you described at first remains: Can it be done in the current animantio nodes versions, or, if not, where can i get a stable 2.1 build for windows 10? And finally, it seems that the given result only applies to a planar plane. will the method work to deformed faces, e.g. those modified by a lattice modifier? Sorry for the request, i'm pretty new to animantion nodes. Thank you very much for your help!! – pixelpoems.de Oct 25 '17 at 20:10
• @pixelpoems.de I updated the answer. Let me know if you need anything else. – Omar Emara Oct 26 '17 at 15:35
• Hi Omar, thank you so much fpr your help. I added a further question (see above) as it is not possible to include images into commnents. Hope to hearing from you soon. – pixelpoems.de Oct 27 '17 at 15:01
• @pixelpoems.de I edited the question and added the blend file. – Omar Emara Oct 27 '17 at 16:26
• Hi Omar, thank you very much for your help. Everything now works as expected. As soon as got more familiar with the settings, i will post a render result here. its really fun to play with animation nodes. Again, thanks a lor for your support !! – pixelpoems.de Oct 29 '17 at 11:55