Curves


Curves take a few tries to learn technique. To make a curve, take your finished product from the last example, and where the rule calls itself, add "rotate 1" as a modifier to when the rule calls itself. You should get a basic swirl. Each time your rule calls itself now, it is rotate by 1 degree counter-clockwise. Not only is the shape rotated, but the axis for which x and y are based are also offset by 1 degree each iteration. So the first circle/square is normal, the second thinks up "up" is also a little to the left, and so on. By the time you get to the 90th, the shapes think "up" means left, and "left" means down. At the 180th shape, they are completely turned upside down, and it continues from there.

The difference between rotating and other modifiers


Other modifiers are multiplied when they are nested (also known as layered or recursed). If you scale a rule by 3, and that rule scales something by 3, your shape is 9 times as large as the original. This is because they are multiplied. If you rotate a rule by 15 degrees, which then rotates a rule by 15 degrees, the shape is only rotated 30 degrees, because it is added together. Trust me, it makes more sense this way when you are creating images. The only additive modifiers are hue and angle, and both are measured in degrees up to 360.

Branches


To create branches, just have a rule call 2 other custom, long winding rules. Such as create a rule the has lines go out at 2 different directions, and have those call other lines. This repeating causes branches and trees.


Other techniques


You can have more than one rule of the same name. When this happens, CF randomly chooses one of the rules, each time it is called. So if you have 3 versions of rule LINE, then each has a 1/3 shot of being called. You can change this by putting a decimal after the name of it, such as "rule line .5". In that case the decimal is the percentage chance that that version will happen, so that version of line would have a 50% chance. You can also mix the two ways, such as having 3 versions, one with a 25% chance, then leaving the other 2 blank. This will make the 2 blank ones equally likely at being called. Any drawing that uses this random choice of rules should be rendered more than once, you will likely get drastically different images the first few times you render it.
//simple tree code demonstrating
//ways to branch off
//using probability
startshape trunk

rule trunk
{
     SQUARE{}
     trunk{y .4 size .99 brightness .005}
}
rule trunk .01
{
     SQUARE{}
//create a tilted branch
     branch {rotate 25}
     trunk{y .4 size .99 brightness .005}
}
rule trunk .01
{
     SQUARE{}
     //create a tilted branch
     branch {rotate -25}
     trunk{y .4 size .99 brightness .005}
}
rule branch
{
     SQUARE{}
     trunk {y .4 size .99 brightness .005}
}

This example shows how you can use probability to make a rule version less likely to be called. It also shows how CF can keep track of multiple parts of the drawing. While we are still building the trunk of the tree we branch off and create branches (which are actually just tilted trunks ;) ). CF has no trouble rendering this. On a last note, look at the double forward slash. This means "ignore everything on this line after the //". We use it as comments, to make sure we can come back and understand what is going on in each area of code. I also threw in the brightness, just in case you hadn't figured it out.

Oftentimes when branching, you will want various different types of rules for different types of branches, this was done using the main trunk rule as a type of branch for 2 reasons: simplicity in design, and to show that really they can be the same.


home | Tutorial 3