From Context Free Art
A CFDG file consists mostly of several rules for drawing shapes using other shapes. There are a few other optional components and one mandatory component:
- A mandatory startshape directive that tells Context Free/CFDG what shape to start with. There must be at least one startshape. If there is more than one then the first one is the one that is used.
- An optional background directive that tells Context Free/CFDG what color to make the background. If there is no background directive then the background is opaque white.
- An optional tile directive that tells Context Free/CFDG to draw a tiled version of the design using the tiling grid specified by the tile directive.
- An optional size directive that restricts the drawing canvas to a specific size and position. Shapes drawn outside this rectangle are cropped.
- Optional include directives that direct Context Free/CFDG to insert another CFDG file at the current position. There can be more than one include directives and included files can include other files.
- One or more shape rules that tell Context Free/CFDG how to draw a shape using other shape rules and primitive shapes. There is no limit to the number of rules. A given shape can also have many rules or just one rule.
- Optional Paths that tell Context Free how to draw a primitive shape.
- Optional comment lines that describe how the CFDG file works. Context Free/CFDG supports C-style block comments and C++ and shell-script style line comments.
Here is an example of all these CFDG file parts:
/* Example CFDG File
This is a block comment. */
// This is one type of line comment
# This is the other type of line comment
startshape Foo // There must be a startshape directive
include stuff.cfdg // Include rules and paths from stuff.cfdg
background { b -1 } // This changes the background to black
tile { s 3 4 } // tile the design on a grid with spacing 3 units wide and 4 units high
//size { s 3 4 x 1 y 2} // Size the canvas 3 units wide and 4 units high, centered on (-1, -2)
// Let us define a rule for shape Foo that is a white square
// containing a black circle. This will be on a black background.
rule Foo {
SQUARE { b 1 }
CIRCLE {}
Bar { b 1 s 0.5 }
}
path Bar {
MOVETO { y 1 }
12* { r (5 * 360 / 13) } {
LINETO { x cos(90 + 5 * 360 / 13)
y sin(90 + 5 * 360 / 13) }
}
CLOSEPOLY {}
FILL { p evenodd }
}
- shape adjustments are used to pass graphical qualities like size, brightness, saturation, rotation angle, and other qualities (if you wondered what the { b -1 } and { s 3 4 } mean, that is it)
After getting familiar with the basics, you might want to proceed to the tutorials. If you have trouble remembering all of the details in the cfdg syntax then check out the reference card.
See also the Context Free cans and cannots.