# Vex shifting values.

## Recommended Posts

Hi.

Probably this is trivial but i don't know how to deal with this in Vex in very optimal way.

I have problem with shifting values in Vex. For example I have a line with points from 0 - 100.

Points have Cd from point 0 - 0 in Cd.r to 100  - 1 in Cd.r.  How to shift this values about custom value? ( If last value is shifted then must go to the begining of my list of points ).

I can do this in loop by checking last value and storing it in temporary parameter , but this is not a very optimal way.

I'm searching for function but I don't see any.

##### Share on other sites

Try the modulo operator:

• 1

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

Modulo indeed a way to go and worth to learn about. Here's some pieces to help with a VEX setup:
vertexprimindex() gives you the index on a primitive and  primvertexcount() gives you max amount. Modulo the first with the second while adding an offset value to the first and you got your carrousel.

Or... you can just shift the points with Sort SOP and read the value from the point with the same newly aquired index. Scene PRB_ShiftAttrib.hiplc

Another example of a setup using Modulo. If confused check the initial explanation.

Cheers

Edited by probiner

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

Thanks. I probably do it wrong but I cant figure out how to do it by modulo operator.

I used sawtooth function. Not to hard to fit this function in range.

Still simple code, but maybe some novice as I, will feel this is a usefull.

```float amplitude = chf("amplitude");

// sawtooth - function with offset about an amplitude. - Begining at 0 and rising up. With animation.

@P.y =((-2 * amplitude)/3.14) * atan(1/tan((@Cd.r + @Time * -0.5 * 3.14)/chf("period"))) + amplitude;```

Yes i like to complicate everything. But this make so fun even if I don't have to much free time.

Edited by Crisis

##### Share on other sites

Sort sop. That is it.

Thanks.

## Create an account

Register a new account