# noise using VEX and for loop

## Recommended Posts

I'm trying to write a VEX script which would apply noise to a geometry using a for loop..(I'm a newbie in VEX so please excuse my lack of knowledge )

basically what I intend to do is to Layer the noise affecting a geometry using its Point numbers as counters in the FOR loop and multiplying it with a Amplitude gain and Frequency gain parameter so that its increasing/decreasing for every iteration (which would thus give me good layer of noise applied on top of each other to a geometry.

here's the scrip so far:

```float amp, freq, again, fgain, sum;
int i;
for(i=0; i&lt;npts; i++)
{
float noise;
float AMP;
float FREQ;
float AMP= amp*again;
float FREQ=freq*fgain;
noise= AMP* noise(FREQ*P);
sum+= noise;
}

Sop
Sop1(amp=0.5, freq=2, again=o.5, fgain=0.5)
{
sum;
}```

I have declared the variables etc..but i'm getting a syntax error in the first line..but I cant see anything wrong with it??

Also I'm not sure of how to execute it in the sop level...so just to check I just called it in the SOP level..but I'm not really sure about it....

could someone help me with this..

Thanks.

PS: here's a .vfl file

Edited by bhaveshpandey
##### Share on other sites

There are quite a few things wrong with your vex code.

Try this:

```//pragmas for your parameters

#pragma hint again hidden
#pragma hint fgain hidden

//if you like to use some custom functions put them here

//the very body of the sop

Sop
Sop1(float amp=0.5, freq=2, again=0.5, fgain=0.5;) // your user parameters.
{

vector PP; //temporary P
float mynoise=0, sum=0;
int i;

for(i=0; i&lt;Npt; i++)
{
mynoise= amp* noise(freq*P);
sum = mynoise;
}

PP = set(P.x, P.y+sum, P.z);
//do something to attributes to see the result:)
P = PP;
}
```

Have a look at houdini help, it's very good.

Edited by peliosis
##### Share on other sites

check the Octaves param, it's available on most pre-built noises and I think it's exactly what you are trying to get.

##### Share on other sites

@Peliosis thanks a ton mate!! i see now where I was going off..

Yep Pencha I was trying to get that done but since I started learning VEX, I thought its better to try and implement it somewhere..I have a long road ahead I guess

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×