Learning Structure Synth

7 min read

Deviation Actions

tatasz's avatar
By
Published:
4.2K Views
A bit more of my Structure Synth learning progress.


Step 6: L-Systems


A quick math break: en.wikipedia.org/wiki/L-system
This is basically what Structure Synth does. Many fractal things can be described using L-systems, so it is a great source of ideas.
As a quick practice, I implemented the Koch Curve, with small edits.

Ls4 by tatasz

#define sc 0.33333333
r1
rule r1 md 10{
{x -1 y 0 s sc} r1
{x -0.5 y 0.5 rz 90 s sc} r1
{x 0 y 1 s  sc} r1
{x 0.5 y 0.5 rz -90 s  sc } r1
{x 1 y 0 s  sc} r1
base }
rule base {{ s 3 0.1 0.3}box}
Here, i used #define to set a scale, so I don't need to type 0.33333... every time I scale down. Just by playing with scales and setting different scales for each dimension, I got a bunch of cool variants, such as:

Ls3 by tatasz Ls1 by tatasz

Or, lets say, the Dragon Curve. Here is my version, with code:

Dragon by tatasz

#define sc 0.70710678118654752440
#define msc -0.70710678118654752440
r2
rule r1 md 10{
{x -0.75 y msc rz -45 s sc} r1
{x 0.75 y msc rz 45 s sc} r2
base }
rule r2 md 10{
{x -0.75 y sc rz 45 s sc} r1
{x 0.75 y sc rz -45 s sc} r2
base }
rule base {{ s 3 0.1 0.1}box}


Step 7: A bit of modeling


Because I never really tried it before.

Tower Preview2 by tatasz

A random tower thingy, work in progress. Rather new to me, so i spent quite a bunch of time in making random shapes and thingies.
Still no reciepe for me, just tons of trial and error. A few things that helped me a lot:
  • references and more references, a full folder of references - I thought i knew how a building looked like, but when I tried to model it out of my head, it looked like minecraft "dirt houses" people build on the first game day.
  • modeling new elements as separate scripts, and then porting them to the main script - less mess, because you work with a small amount of code at a time (the script of the tower above has, for example, 157 lines, and it is the basic of the basic of the structure)
  • using a different color for each element of the structure makes it easier to see what is going on
  • small randomizations make things look way more interesting and natural


Step 8: writing more rules

As things go, i've been needing to write rules all time, so getting skills in this.

For example, I've noticed that sometimes breaking one rule in several parts may actually simplify it a lot. Imagine that, on the picture below, we want to randomize the positions of blocks a bit, so it is not a regular grid anymore.

r_field
rule r_line {20 *{x 2}base }
rule r_field {20 *{y 2}r_line }
rule base {box}


Field by tatasz

An idea would be to create a rule with several different positions for base, and then use this rule to fill the field. Then, lets say, if we set 6 different options, we will have 6 different positions for the block.
Now, lets break this rule down in 2: first, a rule that randomizes position in x, and then a rule that takes the output of the previous one and randomizes it in y. This way, if we set 3 options for each of the rules, we will have same 6 options (2 rules 3 options each) as before, but 9 different final positions. If we set 5 options for each rule, with 10 options overall we will have 25 different positions for the base block.
So basically, creating 2 rules instead of one allows us to have a 10 line script to randomize the positions of the blocks, instead of 25 lines to achieve the same effect with only one rule.

r_field
rule r_line {20 *{x 2}randomy }
rule r_field {20 *{y 2}r_line }
rule randomx {{x 0.1}box}
rule randomx {{x -0.1}box}
rule randomx {{x 0.2}box}
rule randomx {{x -0.2}box}
rule randomx {{x 0}box}
rule randomy {{y 0.1}randomx}
rule randomy {{y -0.1}randomx}
rule randomy {{y 0.2}randomx}
rule randomy {{y -0.2}randomx}
rule randomy {{y 0.1}randomx}
rule base {box}

Fieldrandom by tatasz



Comments7
Join the community to add your comment. Already a deviant? Log In
timemit's avatar
it's great fun .. I wish I understood math/code.. .  it was the only subject i ever failed at :lol: ..  hows this little tweak of the dragon

#define sc 0.6970710678118654752440
#define msc -0.6970710678118654752440
r2

rule r1 md 11{
{x -0.697 y msc rz -45 s sc z -0.699
} r1
{x 0.697 y msc rz 90 s sc
z 0.699 } r2
base}

rule r2 md 11{
{x -0.697 y sc rz 45 s sc
z 0.699 } r1
{x 0.697 y sc rz -90 s sc
z -0.699 } r2
base }
rule base {{ s 3 0.3 0.3}box sphere}