# Dax Phyz Logics Tutorial Part 2

## Creating new vertices (volcano demo)

### NEWV

The NEWV logic constraint in Dax Phyz creates new vertices. We specify the new vert's position with the Lx, Ly registers. We can specify an existing vert in the V register, in which case the new vert will belong to the same object and have the same colour as the existing vert, or let V equal -1 to create a new, separate object with an unspecified colour.

NEWV is inherently edge triggered, which means it runs once per physics frame even if its edge register is 0. In this example, we'll make it PC triggered to be able to control the rate of vert creation.

The NEWV logic will execute when its edge register's value equals the value of logic 3 (PC). The PC logic is an edge triggered INC pointing to itself as usual.

### Repetition

The snippet model above will create just one new vertex, since NEWV is PC triggered (at edge value 1) with a PC which starts at 0 and increases by 1 every physics frame.

We can create multiple vertices by resetting the PC with the CPY logic, which copies a value (v) from one logic to another.

Here, the CPY destination Ld=3 which is the PC. The source Ls=4 which is the CPY logic itself, which has a value v=0.

The CPY logic is PC triggered (using the same PC it modifies) at edge=80. This will reset PC every 80 physics frames, creating a new vertex every 80/125 seconds in Low speed (125 pps).

### Stochasticism

The NEWV logic creates new vertices at the exact location specified by the Lx, Ly registers. To introduce some stochasticism, we can utilize Dax Phyz' stochastic collision simulation to nudge each new vertex as it falls due to gravity.

We use some tightly packed (spacing 2), anchored vertices with a slight asymmetry to hedge in the vertex portal.

If we increase the vertex creation rate (by lowering the CPY logic's edge register from 80), old vertices may not have had time to clear the space in which new vertices are created. If the positions of two vertices in Dax Phyz overlap, a symmetrical explosion is simulated, causing the vertices to move diametrically apart at high velocity. By surrounding the vertex portal as above, we can simulate a directed stream of vertices at high pressure.

### XCPY

When the NEWV logic has executed, its V register points to the new vertex, which will then be used as input to the NEWV logic on its next iteration. Because of this, all vertices will belong to the same object.

In this example, we want each vertex to belong to its own object. To accomplish this, we'll use the XCPY logic. While the CPY logic copies the value (v) register from one logic to another, the XCPY logic copies item connections between logics. Such a connection is a binding to a vertex or a constraint, and is stored in (some) logics as the item's dynamic index (shown in the status bar when hovering over it). No connection is represented by the index number -1 (note that dynamic index number 0 may well represent an item). In a sense, the XCPY logic allows for self-modifying circuits.

We use a second, passive NEWV logic with V=-1 to source the vertex binding to unbound (no connection). Since we want to update the active NEWV with this value before it's used, we delay the active NEWV logic by increasing its edge register to 2, and set the XCPY edge register to 1.

### Colour

The RGB logic takes 3 inputs, specifying the red, green and blue components, and yields the corresponding colour value in its v register. To source the colour components, we can use the RAND logic, which yields a random number between 0 and 1 in its v register. We multiply each RAND value by 255, since the RGB logic expects values between 0 and 255.

To set the colour of a vertex created by the NEWV logic, we use the VCOLW logic, which connects to a vertex logic LV and a colour value logic Lcol. We use the active NEWV as the vertex logic, and the RGB as the colour value logic.

Since we must wait for the vertex to be created before we can set its colour, we PC trigger the VCOLW logic with edge=3.