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.
#define sc 0.33333333Here, 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:
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}
Or, lets say, the Dragon Curve. Here is my version, with code:
#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.
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}
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}