# Nuke wave expressions to copy and paste

## Using waves to drive animation in Nuke

Creating repeating or random patterns in the curve editor can often be made easier by using expressions that describe a curve. Sine, noise and random functions are very useful, but forcing them into the exact shape you want can be a little time-consuming. So, following my previous post talking about my gizmo WaveMaker, I thought I’d share some handy expressions it uses which you can copy and paste straight from this blog when you need them, rather than installing the gizmo itself.

Edit on 12/10/2013: I have just released Animation Maker, a handy Nuke extension that contains all the waves talked about here, plus lots of Ease curves too. See the article here.

Click on any value in any node, press ‘=’ and type an expression. Right click and choose ‘Curve Editor…’ to view the curve.

These expressions give you full control over the width, height and position of the wave. Either replace the following variables with your actual values, or add your own sliders to the node so you can adjust them on the fly (see below for how to do that).

waveLength (how many frames between peaks of the wave)
minVal (the wave will never go below this value)
maxVal (the wave will never go above this value)
offset (shift the wave back and forth in time)

Edit on 15/01/12: I have also provided simple versions that will work immediately once you paste them in. They will just produce a wave between 0 and 1 but that may be all you need.

## Some useful wave expressions:

### (((sin(((frame*(pi*2/(waveLength/2))/2)+offset))+1)/2) * (maxVal-minVal) ) + minVal

Simple version:  (sin(frame/5)/2)+0.5  (Wave between 0 and 1, replace the ‘5’ to adjust speed)

### Square ((((sin(((frame*(pi*2/(waveLength/2))/2)+offset))+1)/2) * (maxVal-minVal) ) + minVal) > ((maxVal/2)+(minVal/2)) ? maxVal : minVal

Simple version:  (sin(frame/5)/2)+0.5 > 0.5 ? 1 : 0  (Wave between 0 and 1, replace the ‘5’ to adjust speed)

### Triangle (((((2*asin(sin(2*pi*(frame/waveLength)+offset)))/pi) / 2)+0.5) * (maxVal-minVal) ) + minVal

Simple version:  (((2*asin(sin(2*pi*(frame/30))))/pi) / 2)+0.5  (Wave between 0 and 1, replace the ’30’ to adjust speed)

### Sawtooth ((1/waveLength)*(((frame-1)+offset) % waveLength) * (maxVal-minVal) ) + minVal

Simple version:  ( 1 / 30 )*( (frame-1) % 30)  (Wave between 0 and 1, replace the two ’30’s to adjust speed)

### Random ((random((frame/waveLength)+offset)) * (maxVal-minVal) ) + minVal

Simple version:  random(frame/5)  (Wave between 0 and 1, replace the ‘5’ to adjust speed)

### Noise (((1*(noise((frame/waveLength)+offset))+1 ) /2 ) * (maxVal-minVal) ) + minVal

Simple version:  (noise(frame/5)/2)+0.5  (Wave between 0 and 1, replace the ‘5’ to adjust speed)

### Bounce ((sin(((frame/waveLength)*pi)+offset)>0?sin(((frame/waveLength)*pi)+offset):cos((((frame/waveLength)*pi)+offset)+(pi/2))) * (maxVal-minVal) ) + minVal

Simple version:  sin(((frame/10)*pi)) > 0 ? sin(((frame/10)*pi)) : cos(((frame/10)*pi)+(pi/2))  (Wave between 0 and 1, replace the ’10’s to adjust speed)

### Sawtooth (parabolic) ((sin((1/(pi/2))*(((frame-1)+offset)/(waveLength/2.46666666)) % (pi/2)))>0.99999? 1 : (sin((1/(pi/2))*(((frame-1)+offset)/(waveLength/2.46666666)) % (pi/2))) * (maxVal-minVal) ) + minVal

### Sawtooth (parabolic, reversed) ((cos((1/(pi/2))*(((frame-1)+offset)/(waveLength/2.46666666)) % (pi/2)))>0.99999? 1 : (cos((1/(pi/2))*(((frame-1)+offset)/(waveLength/2.46666666)) % (pi/2))) * (maxVal-minVal) ) + minVal

### Sawtooth (exponential) ((((((exp((1/(pi/2))*(((frame-1)+offset)/(waveLength/4.934802)) % pi*2)))/534.5)) – 0.00186741)>0.999987? 1 : (((((exp((1/(pi/2))*(((frame-1)+offset)/(waveLength/4.934802)) % pi*2)))/534.5)) – 0.00186741) * (maxVal-minVal) ) + minVal

*Note: the waveLength value doesn’t really correspond to the peaks in Random or Noise waves, so you will probably need a smaller wavelength value for those.

1. Right click your node, choose ‘Manage User Knobs…’
2. Click ‘Add…’ and choose ‘Floating Point Slider…’
3. Type ‘waveLength’ into its name and label boxes. Give it a max and min value of 0 and 100.
4. Repeat with each of the four variable names (above).

These  four sliders will appear in the ‘User’ tab of the node. You may find it better to create a ‘NoOp’ node, add the above sliders, but also add several extra floating-point sliders called ‘Wave1’, ‘Wave2’, ‘Wave3’ etc. This way you can use the same sliders to control several different expressions, then you can use any one of them to drive animations in your script.

It’s worth noting many of these wave shapes can be created using a few keyframes and telling nuke to ‘loop’ that section. But using expressions with a few sliders you can mess around with them a lot easier. Besides, maths is fun.

## One more thing:

To describe a CIRCLE, put this in the X:

(((sin(((frame*(pi*2/(waveLength/2))/2)+offset))+1)/2) * (maxVal-minVal) ) + minVal

and this in Y:

(((cos(((frame*(pi*2/(waveLength/2))/2)+offset))+1)/2) * (maxVal-minVal) ) + minVal

Simple version (X): sin(frame/5)*300

Simple version (Y): cos(frame/5)*300

(replace the ‘5’ to adjust speed, replace the ‘300’ to change the circle size)

Tip: put it in the X and Z in a TransformGeo after a Card to make a carousel type animation. About davemne
VFX artist from the UK.

### 21 Responses to Nuke wave expressions to copy and paste

1. zhiyong says:

hi,Davemne~
i was try to use the expressions,but there is an error in the “Sawtooth (exponential)”
the others are fine,no any problem,
i was so carefully to copy,but not work,

• davemne says:

Hi zhiyong,

Thanks for spotting that problem. I’ve looked at it and it seems wordpress was choosing the wrong type of “-” in the expression, so nuke doesn’t recognise the ascii character. I’ve updated the post, so if you refresh, you should see the minus symbols change from long to short ones. If your browser still doesn’t show the new expression, you can manually replace both minus symbols with a normal minus symbol. That should fix it.

• zhiyong says:

ok，it’s work~
Thank you~

• zhiyong says:

I’m so sorry…i was copy this tutorial to my blog，and then copy the expression From that web，it was error；
so，if you don’t care please Delete my rely~
at last，I‘m so sorry~
i’m a compositor from China，
thanks for sharing~ ：）

2. feilong says:

these are immensely useful. thank you.

3. nuverian says:

Thanks..Very usefulll 🙂

4. falk says:

thank you very much. they are quite usefull. in my case i build up some panel to choose the specific wave and create the proper user tab. reminds me of the modifiers inside of fusion.
thanks again.

5. Karnage says:

Really useful! Thx a Lot!

6. Nick says:

How would I go about making a blink expression? And to have that blink happen every X frames, cheers! If I figure it out before I get a reply I’ll be sure to post!

• davemne says:

Blink expressions would be the same as a square wave, which you can see above. So paste this into your expression: (sin(frame/5)/2)+0.5 > 0.5 ? 1 : 0

Blinks on and off between 0 and 1. Adjust the ‘5’ in there to set the speed of the blink. This expression takes a normal sine wave, which goes up and down regularly and turns it into a square wave by changing everything below 0.5 to 0 and everything above 0.5 to 1. You can turn any kind of curve into a square version like this by using that formula:

(myExpression) > halfway point ? maximum value : minimum value

Translates to:
“Is the current value at this frame greater than the halfway point? If so, set the current value to the maximum, otherwise set it to the minimum”.

7. Carlos Patrick De Leon says:

Words cannot say how much this helps me. You have my thanks, forever!

8. pankaj says:

hi David Emeny im pankaj sr compositor any example for how to compile gizmo convert to dll or ofx file for nuke supported

9. CameronC says:

Hi David,
I’m a Nuke compositor in the Portland, OR area and I just wanted to thank you for this post I discovered it about a year or two back and have had it bookmarked ever since. I use expressions all the time and having a cheat-sheet is immensely useful. I did want to mention however after using a few of yours for a while a revision or two that would be useful. First in your expressions, I will use the sine wave as an example, the offset is not truely time based as you might have noticed. I have corrected this with this slight revision, “(((sin(((frame*(pi*2/waveLength)/2)+(offset/waveLength*pi)))+1)/2) * (maxVal-minVal) ) + minVal” the only change being divide the offset by the waveLength and multiply by pi. this just allows the offset to be relevant and corresponding with the actual frame offset of the expression. This goes for pretty much all of your waves.

Oh and your Sawtooth (exponential) expression uses long dashes (–) instead of minus signs (-) so copy paste doesn’t quite work. haha

Thought you would like to know!

Also I hope you don’t mind me making a similar post like this on my site. or somewhere. I just feel like a cheat sheet like this is so useful.

• CameronC says:

Oh Sawtooth Expressions are fine with current offset by the way it’s just the rest

• davemne says:

That’s fantastic, I’ll definitely check out your modified expressions. Glad you find them useful and please feel free to add and improve on them. If you give me a link to your site I can perhaps add revised versions of the expressions with a link crediting you.

Thought I’d fixed the long dashes problem, seems WordPress is determined to convert the minus signs when I publish. Will see if I can fix that when I get a chance.

• CameronC says:

Here’s a link to my site with the revised expressions. Feel free to copy paste as much as you want. I have refined and simplified most of them. Just removing unnecessary parts and such.

https://cameroncarson.com/nuke-wave-expressions/

10. Pingback: expressions | eleanor nuke training

11. Ross Gilbert says:

Hi mate..
Thanks so much I use this page weekly for copy/paste wave expressions, but now I have a question!

I’m using a sawtooth wave to create an oscillating y transformation, but wonder about a way to get a new wavelength every cycle?? So for each oscillation i get a random speed….

Anyway thanks soo much.
Ross