# Getting Started With Expressions (Part 3/3)

We are back with expressions! 🙂 In the last two lessons we learned how to use expressions for many different applications. You might have noticed that we’ve only used three functions so far: sine, cosine, and random. Of course there are many more functions, and you can find them in the “Curve Editor” under **Insert > Unary functions**. They work in exactly the same way as the functions we have discussed already.

The last part of our mini-series sheds some light on the creation of spirals. Spirals are, for example, perfectly suited for nicely shaped patterns of caramel or honey, or you make a camera surround a collapsing tower.

#### A Perfect Circle

There are dozens of different types of spirals and we have to focus on simple shapes, because every spiral is defined through an individual formula – and these formulas can be very complex.

Again, a circle is the starting point for our considerations on spirals, and therefore we recommend reading the previous chapters of our blog about expressions. As always, everything’s based on RealFlow’s YXZ setup. Users with Z-based setups have to replace Z through Y.

Create a null, and right-click on its “Position” parameter and choose “Edit Curves…” to open the “Curve Editor”. The following two expressions will create a circle with a radius of 1:

Position.X sin(t) Position.Z cos(t)

For Z-based setups the expressions are

Position.X sin(t) Position.Y cos(t)

#### Archimedean Spiral

In an Archimedean spiral the distance between the spiral’s arms is constant, and the common formula for this type is:

Position.X radius*t*sin(t) Position.Z radius*t*cos(t)

What we get here is a wide, and quickly growing spiral. The reason why this formula creates a spiral form at all is that t increases over time. The radius is responsible for the spiral’s width and global scale. With radius values smaller than 1 the spiral will become narrower.

If you have read the first two parts of our series you will recognize that this formula is not complete, because it lacks frequency – or better: the number of convolutions. Higher frequency values create more convolutions and the spiral will become “denser”. So the complete formula is:

radius*t*sin(t*frequency) radius*t*cos(t*frequency)

By using negative radius values we are also able to change the spiral’s direction of rotation (clockwise, counterclockwise). Of course it is also possible to merge parts of the expressions from the previous blogpost with the spiral formulas to achieve even more control.

#### Damped Spirals

In the first lesson of our series we have been discussing damped oscillations: this type of oscillation starts with a big amplitude and decreases over time, and it is based on a sine/cosine function. That’s perfect and another advantage is that we’re familiar with the formula and its parameters already. So all we have to do is to create another null and apply the following expressions to the horizontal position coordinates:

5*exp(-t*0.25)*sin(4*t) 5*exp(-t*0.25)*cos(4*t)

The first factor (5) defines the spiral’s radius, and the third factor (4*t) the number of convolutions. This type of spiral is not only good for honey or cream, but also if you want to coil up ropes, for example. As you can see, the spiral’s arm become narrower over time and this also is good for simulations of soft ice.

#### Helices

A helix is a 3-dimensional spiral, and all you have to do to get them, is to move the object along its vertical axis. This can be achieved with animation keys or with another expression. The easiest one is

heightfactor*t

With heightfactor it’s easy to control how quickly the object will be moving. Values, smaller than 1, will make the object move slowly. And the bigger the value, the faster the motion. In the video below you see a rotating bitmap emitter moving along a helix.

#### Conclusions

As you have seen it doesn’t take too much to get some really nice results with basic functions. RealFlow’s expressions are incredibly versatile and they also help to save a lot of time, because you just have to change a few parameters, not an entire animation curve. Sure, it sometimes takes a little time to find appropriate formulas, but in most cases you just need basic math, not rocket science.

For repetitive or linear motions, wiggle effects, rotations, randomization, falloffs, switches, or spirals there’s really no better way than expressions.

## 0 Comments