📜 ⬆️ ⬇️

Introduction to Structure Synth

Structure Synth, Virus
Hello, habr. Yesterday I was playing with a new Ubuntu 11.10 and quite by chance I came across such a wonderful application, like Structure Synth. Structure Synth has already been discussed in Habré, and I would like to sketch free-literary translation of a short tutorial from the official site.


What is he talking about?

Structure Synth is a cross-platform application for building complex three-dimensional structures. Structures are built by executing a set of rules in the Eisenscript language. The grammar was originally developed by a man named Chris Coyne and is used in the application for constructing two-dimensional images Context Free Art . Structure Synth is written in C ++ using OpenGL and Qt. Builds are available for Windows, Mac OS and Linux.

States, transformations and actions.

The cornerstone in the SS is the state . The state describes the current coordinate system and coloring mode. The coordinate system determines the position, orientation and size of all objects created in the current state.
')
The state is modified by transformations . For example, we can shift the current coordinate system by one along the X axis by applying the transformation { x 1 } . In the same way, the coordinate system can be rotated 90 degrees around the X axis with the transformation { rx 90 } . Transformations are combined during parsing, so { x 1 x 1 } equivalent to { x 2 } .

The state can be combined with calling up rules by creating actions . For example, { x 2 } box is a transformation followed by a rule. The built-in rule “box” will create a cube in the coordinates (0, 0, 0) -> (1, 1, 1) in the current coordinate system.

Let's take a look at this example:

box
{ x 2 } box
{ x 4 } box
{ x 6 } box


The result will be something like this:

4 boxes

The code from the example above creates four cubes with equal intervals. Please note that we define several actions one after another. Each action is applied to the same state - in our case, the original. Actions do not apply to the state created by the previous action.

Iterations

It is possible to describe multiple actions ( iterations ) using the multiplication symbol. For example, 3 * { x 2 } box completely identical to the code from the first example.

Color Transformations

We can change the current rendering color in the same way as we apply spatial transformations. Structure Synth uses the HSV scheme (Hue, Saturation, Value) to represent color. The hue , sat/saturation and b/brightness operators are used to transform the color.

An example demonstrating iteration and color transformation:

10 * { x 1 hue 36 } 10 * { y 1 sat 0.9 } 10 * { z 1 b 0.9 } box

Result:

Colored Cube

Another example with different transformations:

10 * { x 2 } box
1 * { y 2 } 10 * { x 2 rx 6 } box
1 * { y 4 } 10 * { x 2 hue 9 } box
1 * { y 6 } 10 * { x 2 s 0.9 } box


Result:

Misc

Embedded rules

box is just one of the primitives - built-in rules - in Structure Synth. At your disposal are also: sphere, dot, grid, line, cylinder, mesh, cylindermesh .

Here are some primitives (left to right: mesh, grid, line, dot, box, sphere):

Primitives

Custom rules

User rules are the key to creating complex and intricate structures. Rules are set using the rule keyword. The user rule is used in the same way as the built-in one. An important feature of the rules - the rule is capable of causing itself . Take a look at the following example:

R1

rule R1 {
{ x 0.9 rz 6 ry 6 s 0.99 sat 0.99 } R1
{ s 2 } sphere
}


What will result in:

Spheres

Note that the R1 rule recursively calls itself. Logically, this code will never complete, but in Structure Synth, there is a maximum allowed recursion depth (by default, 1000 recursive calls). Achieving the maximum depth of recursion can be considered the achievement of the base of recursion. The maximum recursion depth value can be changed using the set maxdepth xxx . Another way to force recursion is to set the maximum number of objects using set maxobjects xxx .

Random

In order to make the structures more interesting, we add something less static - we add randomness. In SS, randomness is achieved by defining several rules with the same name. For example:

R1

rule R1 {
{ x 0.9 rz 6 ry 6 s 0.99 sat 0.99 } R1
{ s 2 } sphere
}

rule R1 {
{ x 0.9 rz -6 ry 6 s 0.99 sat 0.99 } R1
{ s 2 } sphere
}


In this example, the rule R1 is defined twice. Now, whenever it is necessary to call such a rule, one of its implementations will be randomly selected. Executing the example above may give, for example, the following result:

Random spheres

Afterword

On this, perhaps, everything. I hope that I was able to attract the attention of habrabschestva to Structure Synth and in the near future we can expect the emergence of new intricate intestines of creations.
A couple of related links:

Source: https://habr.com/ru/post/131704/


All Articles