# Vex - smooth interpolation of random values

## Recommended Posts

art3mis    29

Trying to learn VEX.

Using the following simple formula in a wrangle to create random green color values on geometry

```@Cd = 0;

@Cd.g = rand(@ptnum);```

Lets say I want different random values at frame 120 and I want the values to smoothly interpolate between frame 1 and 120.

How would I do this?

##### Share on other sites
symek    266

This is what noise functions were designed for: http://www.sidefx.com/docs/houdini/vex/random

They are also available in VOPs (look in Tab menu under "Patterns" category). Noise function smoothly interpolates both in space domain and time domain (pseudo)random values.

##### Share on other sites
rich_lord    160

Unless I'm misunderstanding your question, you could also do this. It will interpolate between two green values over the frame range 1-120

// create first random value

float value1 = rand(@ptnum);

// create second random value

float value2 = rand(@ptnum + 325);

// interpolate between thoose two values over the frame range

float current_value = fit(@Frame, 1, 120, value1, value2);

// set that to the current colour

@Cd = set(0, current_value, 0);

##### Share on other sites
art3mis    29

Szymon, thanks. I wasn't aware of this! Wow, very powerful

Thanks Richard. Got it. So essentially using frame value to drive interpolation. How might you use time value to accomplish the same thing?

##### Share on other sites
rich_lord    160

@Time is the current time in seconds. So @Frame = @Time * 24. If your frame rate is set to 24frames per second.

Therefore they are pretty interchangeable, and accomplish the same thing. Personally I always use @Frame and would only use @Time for sub frame stuff, which I never really need.

##### Share on other sites
ikoon    102
Posted (edited)

Btw as you have mentioned "smooth", this VEX function came to my mind:
http://www.sidefx.com/docs/houdini/vex/functions/smooth

As it says:

- smooth (easin and easeout) interpolation is computed
- If a rolloff is specified, the inflection point of the blend will be shifted.

Once I wanted just ease-in (no ease-out), Python has it (http://www.sidefx.com/docs/houdini/hom/hou/ease) but VEX probably doesn't. I have quite solved it with VEX and that biased rolloff.

Edited by ikoon
edit: btw Jim, I think that you will like chops, try Matt Estela's intro to chops

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account