Shape rules

Shape Rules
Shape rules describe how to draw a given shape. A shape is composed of some number of primitive shapes (squares, circles, and triangles) and non-primitive shapes. There must be at least one rule for each shape referenced or Context Free/CFDG will give you an error. A rule has the word rule followed the name of the shape being defined and then the shape replacements in curly braces. There can also be an rule weight between the name and the left curly brace. If the rule weight is omitted then the default weight of 1 is used. Rule weights must be positive real numbers.

After Context Free/CFDG picks a rule it executes it by drawing each of the shape replacements contained within the rule. Primitive shapes are drawn right away and non-primitive shapes are put in the evaluation queue and drawn later.

Overlapping Shapes and the Order of Drawing
There is no guaranteed order to the drawing of shapes. The currently implemented rendering algorithm renders larger shapes first, so smaller shapes will be drawn later, on top of them. But this must not be relied upon, as the algorithm has changed in the past and may change again. There are only two guaranteed orders to drawing: primitive shapes in a rule draw in order before anything else, and shapes with a larger z-axis coordinate draw on top of shapes with smaller z, regardless of when they were rendered.

Randomness, Rule Weights, and Having Multiple Rules for a Shape
If there is only one rule for all the shapes in a CFDG file then the result will always look the same. But when there is more than one rule for a given shape then Context Free/CFDG has to choose which one to use at random. The probability that a particular rule will be used is proportional to its weight. The exact equation is the rule's weight divided by the sum of the rule weights for the given shape. Another use for multiple rules is to provide an ending condition to an infinite recursion: