# A simpe pscale VEX problem I can't solve

## Recommended Posts

Being quite new to Houdini and VERY new and completely out of my depth in VEX I have a problem which should be simple for anyone who is smart. So the setup is I have some popgrains spawning on an object that scale from 0.001 up to 0.025 using some VEX and then having those grains stick to the surface of the context geometry. Using the following code...

```@pscale += 0.001;
@pscale = clamp(@pscale, 0, 0.025)*1.5;
int pr;
vector uv;
float d = xyzdist(1,@P,pr,uv);
@P = primuv(1,'P',pr,uv);```

This works fine and spawns particles that grow to all be a uniform size. My question is. What do I add or how do I change that code to add some randomness to the size that the grains scale up to. I have tried to wrap my head around the "rand" function inside the clamp function but ended up making everything explode into giant grains.

I KNOW there is a simple solution to this but not having the brain for code just yet out of pure ignorance I don't know what to do. Could anyone help possibly?

ALSO as a bonus for anyone who is super genius. Is there a way to define a determined number of sizes the pscale of grains can be? For example have 5 different sizes that a grain can be based on a seed or even better a probability so I can control how many of each sized grain could show up at spawn?

ALSO ALSO if you could help me with this, Can I use VEX to assign Cd values to each size clone to have the ability to have different materials on different grains based upon their size.

It seems like I'm asking a lot but I'm sure someone here is thinking "Pftt this is just 3 lines of code." And could help me work it out.

##### Share on other sites

The Docs have an Example File for what are trying to achieve.

##### Share on other sites

Hey Aaron,

I've done a simple SOP solver setup on just some basic spheres, but you can apply the same code to your setup if this is what you're looking for

For the points to have some random pre-defined max sizes you can create an array of floats (the random sizes you wish to have), then create a random integer variable (between 0 & the length of the array) for each point to be used as the index of that array. Then all you have to do is to change the max parameter of the clamp() to be that. Meaning each points will have a random max size taken from the array.

Hope this helps!

• 2

##### Share on other sites

This is a glorious set up. I love it. To add some "Art Direction" to your existing setup is there a way to set up ratios to the randomness? Like could I have 60% small particles 20% to the medium particles 15% of the medium large particles and 5% large particles? Or some kind of simular way to sort of control the amount of each size?

##### Share on other sites

Hi,

I've updated the setup so now you can control the probability for each specified size as you suggested

I'm sure there are other ways of doing it, but this is the method I had in mind.

• 1

##### Share on other sites

I think this little setup is so awesome and it's such a common thing in these little simulation and pretty instagram renders. I'm wondering with your permission I can post the setup to the "Houdini Blueprints" website. Or if you want to do it yourself for all the credit and prestige. I think it would help a lot of people.

##### Share on other sites

Yeah of course! I don't mind at all, feel free to post it anywhere!

## Create an account

Register a new account