The basics

Every Context-Free drawing, or CDFG for short, is comprised of one or more "rules" dictating what to do. To tell which rule to start with, we use "startshape". Let me show you with a couple of examples, and explain from there. You can even copy this over to CF and hit "Render" just so you can make your first CDFGs :) .
starshape ci
rule ci { CIRCLE{} }

startshape sq
rule sq { SQUARE{} }

These two examples are the most basic CDFGs, a square and a circle. Each CDFG needs at least one rule, because you need to draw something. We designate a rule by writing "rule", the name of it (in this case either "ci" or "sq"), and then describing the rule inside brackets. Names must be longer than one character, but may not contain spaces, so if you use descriptive names, use the underscore to break apart words. Also, note you cannot create rules while inside a rule, you must finish one before starting another. The startshape command tells us where to start, and is generally the first line of code (makes things easier to read). You may have noticed a lot of brackets. Brackets tell us what describes your rule. They are also used after calling a rule (in this case consider SQUARE and CIRCLE to be types of rules). In this example they are empty, but this is where you adjust a rule as you 'call' it.

Confused? Let me try to explain: we are telling CF start the shape with ci. Then we are telling it, create a rule, name it ci, and whenever you want to do ci, draw a circle.

lets do some more with this.
startshape cf
rule cf { SQUARE{} CIRCLE{x 2} }

Lets dissect that, we now have a rule which has 2 shapes in it, one with "x 2" in its brackets. Render it. Notice that the circle is now to the right of the square. And the space between the two is exactly the same size they are. Change the 2 to a 1. Change the x to a y. Are you getting it? You can also mix the two, as well as use negative numbers to go the opposite direction. The descriptions inside the brackets change how you draw the rule. Notice that x goes right and y goes up. Easiest way for me to remember this is to stick out my left hand, palm facing away from me. The direction my fingers and thumb point are upwards for the numbers, so up for y and to the right for x.

Now we are gonna move on to a bigger step:
startshape ab
rule ab
     cd{x 1 size .5}

rule cd
     ef{x 1 size .5}

rule ef

Hopefully this formatting makes it easier to read and understand. Notice in this example there are multiple rules, and a new modifier: size. This example brings about an odd concept: relativity. Render the above CDFG and notice something, ab is on the left, cd is in the middle, and ef is on the right. Ab is the largest, and ef is the smallest. Look at the text too, we call cd as being .5 size and a x position of 1. We do the same for ef. So if they are both size .5 and x 1, why dont they overlap? And why arent they the same size? Its because we are saying that we want cd to be .5 the size of ab, and we want it to be 1 to the right of ab. Then when we're in the shrunken moved over world of bc, we say we wanna shrink ef and move it to the right. But were already shrunken and moved to the right, so it gets shrunken again and moved to the right again. It ends up 1/4 the size of ab, because its been cut in half twice. You can also scale things larger, by simply using "size" with a number greater than 1.

For the final part, you do it yourself. Create a shape, a new one. You will then need a rule. Have the rule draw either a circle or square (which is always capitalized). Move the circle or square in any direction by .2, and scale it by .995 . Finish the rule by having it call itself. Render it. You should end up with a tapering line. Notice how CF automatically rescales the image. Also, note what you would think would happen if you didnt scale the shape. CF keeps going until its working with such tiny pieces that they wont show up compared to the larger parts of the image. So if you did not rescale it, CF would keep drawing, forever adding to an infinitly long line. I chose the numbers .2 and .995 because they create a long smooth line, too large of an X and it gets bumpy (esescially with circles).

One last modifier for you: brightness, back from before color. Expirament with it on how to make things brighter or darker, ok? You're at the point where you can self-teach. I have faith in you.

Final note: CF now offers 2 dimensional scaling. Following s or size, you can have 2 numbers, with a space between the two. They can scale the image in the x and y independantly. This means "size 2 .5" would make the next rule twice as long and half the height. It would show up with the height a quarter the size of the width, because the width is doubled and the height halved.

home | Tutorial 2