The secret sauce

Cavalry's architecture does some amazing and unique things. On the surface this means you can do more with less elements but what's actually going on under the hood?

The underlying concept to understand is that of an Index. An index is simply a number passed to another Element. A fundamental part of a Duplicator's role is to assign indices to the Shapes it generates. This index can be used by the Duplicator and other Elements to dictate position, rotation, color, number of sides...anything really.

Let's say you've used a Duplicator to create a column of 10 rectangles.

In this case the Duplicator creates 10 indices and uses them simply to provide each duplicated Shape with a position based on the Distribution settings (in this case a Grid with a Height of 350 and a Size mode of Fit). Index:0 (the first shape) gets assigned a Position Y of 0 and Index:9 (the tenth/last shape) gets assigned a Position Y of 350 with the other Shapes distributed evenly between.

Ok, so what happens if we add this Duplicator to a second Duplicator? Here the second Duplicator has been set to a Grid of Count X = 5 and Count Y = 1.

As you can see the indices flow through to the second Duplicator's shapes. As you keep duplicating Duplicator's this index count will keep flowing through the graph.

So how about a practical example.

  1. Create a Text Generator.

  2. Set the Generator to Value.

  3. Add the Text Generator to a Duplicator.

  4. On the Grid Distribution set the Count to X = 1, Y = 10. Result: A column of zeros.

So, on the surface, there's nothing very interesting going on there 😉 but that's just because we've not asked the Duplicator to do anything with the indices. So let's ask it to create some random values to pass to the Number attribute.

  1. Create a Random Behaviour.

  2. Connect > textGenerator.number. Result: Each number is a random number between 0 and 10 (defaults).

The Duplicator passes random numbers to each duplicate.

The above is made possible by the fact that the Duplicator provides a Index to each number and the Random node utilises that context.

  • Duplicator asks Text Generator 10 times for its Number.

  • In turn, Text Generator asks Random 10 times for the value of its Number.

  • During those 10 times, Random receives Index values of: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

  • Based on each index, Random alters its Seed value to produce different results.

You can apply this idea to any attribute in Cavalry. Let's do the same thing to affect the number of sides of a Polygon.

  1. Create a Polygon Shape.

  2. Add it to a Duplicator.

  3. Add a Random Behaviour.

  4. Set Minimum to 3 and Maximum to 5.

  5. Connect > polygon.sides.

Each shape is given a random number of sides of between 3 and 5.

This concept can be used on Noise Deformers, Colors, Stroke Widths, Path Lengths, Blur Filters, Asset Arrays, Dynamic Rendering...anything. The possibilities are endless! 😎

Switching to manual

Now there are occasions when you might want manual control of how these indices are assigned. There are two levels to this. The first is to prevent the Duplicator from using the 'incoming index'.

Taking our example of a grid of rectangles (the duplicated Duplicator):

  1. In the Attribute Editor, right-click on Duplicator1's header bar and uncheck Advanced -> Use Incoming Index.

Now the indices from Duplicator1 are being cycled through to the second Duplicator.

To take this idea even further you will need the help of the Context Index Atom.