# VEX

Some useful VEX.

SOP Rotations Around Axis

### DOP Random Air Resistance

This one-liner will simply add random air resistance per particle within the minimum and maximum values

`airresist *= fit01(@id,0.05,1);`

### DOP Random Spin

This adds random spin to particles – put it in the popspin DOP

```//Add Min and Max controls to node
axis = rand(@id) - set(0.5, 0.5, 0.5);
spinspeed *= fit01(rand(@id+0.1), ch("Min"), ch("Max"));```

### SOP Build Matrix

These wrangles will build a matrix, move the animated geo to the origin and then revert it back to it’s original world space.

```vector centroid_position = chv("centroid_position");
matrix xform = invert(maketransform(0,0,centroid_position, {0,0,0},{1,1,1},{0,0,0}));
@P *= xform;
4@xform_matrix = xform;
```

`@P *= invert(4@xform_matrix);`

### SOP Fake Collisions Wrangle

This fella will push points within a volume outside of the volume. Pipe the collision SDF into the second input.

```vector grad = volumegradient(1, 0, @P);
float dist = volumesample(1, 0, @P);
if(dist <= 0)

### SOP Delete Points by Threshold

This snippet will delete random points based on the threshold slider. Taken from http://www.tokeru.com

```if ( rand(@ptnum) > ch('threshold') ) {
removepoint(0,@ptnum);
}```

### SOP Create Lines Network

This snippet will create a network of lines based on distance threshold. Taken from Entagma’s “Creating Geo With Vex”  video

```float searchrad = ch("rad");

int nearpnts[] = nearpoints(0, @P, searchrad);

foreach(int pnt; nearpnts){

}```

### SOP Random pscale with Ramp, Seed, Min and Max

This useful little dude will create a ramp that can be used with minimum, maximum and seed values to generate random pscale values with weighting.

```@pscale = fit01(chramp("Width", rand(@id  + ch("Seed"))), ch("Min"), ch("Max"));
```

A corresponding Attribute VOP would look something like this:

### SOP Random Rotation Wrangle

A basic random rotation wrangle

```float angle = ch("rot_amount");
float rand = fit01(random(@ptnum+311),0,angle);

### SOP Rotation Wrangle

This guy will enable randomised rotations on particles. Add a time variable (\$T/\$F) into the angle input to get them moving.

### SOP Spiral Curve

Makes input curve into a spiral with controls

```@P.x = cos(@ptnum * ch("frequency")) * ch("amp_x") + ch("offset_x");
@P.y = @ptnum * ch("amp_y");
@P.z = sin(@ptnum * ch("frequency")) * ch("amp_z") + ch("offset_z");```