CFDG: Description and Syntax [Home]   [Syntax]   [Images]   [Links]


Basic syntax

CFDG programs consist of one or more rule definitions and [optional] initial assignments:
  parameter1 = initial_value1
  parameter2 = initial_value2
  ...
  startshape initial_rule_name
  rule rule_1 {
    rule_A { parameter1 value1 parameter2 value2 ... }
    rule_B { parameter1 value1 parameter2 value2 ... }
    ...
  }
  rule rule_2 {
   ...
  }
  ...
Rules define a set of instructions, i.e. calls to other rules and/or built-in routines, such as CIRCLE.
They may be called with optional parameters enclosed in { } or ( ) that define changes in size, color, shift or rotation (listed in this table).
Their initial values may be changed by assignments before rules' definitions.

The following built-in rules are available:
CIRCLE: filled circle;
SQUARE: filled square;
RECT: empty square;
LINE: line segment.

Multiple versions of each rule are supported. In this case CFDG will pick a random version.
You may optionally specify weightings (probabilities) for each rule's version (see below).

Script execution starts with initial rule (start shape), defined with startshape rule_name.

Keywords, rules' names and parameters are case-insensitive, e.g. startshape First means the same as STARTSHAPE FIRST.

Parameters may be contracted to their first letter, e.g. Foo {s 2} is the same as Foo {size 2}.

Line breaks, spaces and tabs are allowed throughout the code.
Spaces are mandatory only between parameters and their values, e.g.: Foo { x2 } //this is an error.

Comments begin with // to the end of the line, e.g. SQUARE {r 30} //draws a square rotated by 30 degrees.
Example 1
nesting = 3  //limit recursion to three levels

startshape Circles

rule Circles {
  FourCircles
  SQUARE  //this will be drawn just once
}

rule FourCircles {
  CIRCLE {x 1.5 s 0.7}
  CIRCLE {x -1.5 s 0.7}
  CIRCLE {y 1.5 s 0.7}
  CIRCLE {y -1.5 s 0.7}
  FourCircles {x 1.5 s 0.5}
  FourCircles {x -1.5 s 0.5}
  FourCircles {y 1.5 s 0.5}
  FourCircles {y -1.5 s 0.5}
}

Advanced features (under construction)

Parameter N limits the recursion level.
If it takes too long to generate your image, try to reduce this parameter or simplify your script.

Infinite loops are okay, as long as the shapes get infinitely small.

You may specify the weighting (probability) for any rule version.
Put the weighting (0 to 1) after the rule name, e.g. rule Branch 0.25 {...} //will be selected approximately in 1/4 of cases.
By default all rules have equal weightings.

Example 2. (to be continued...)

The following table lists all supported parameters and their possible values.

Name Range Default Parameter Value Formula Description
A (alpha-channel) 0 (opaque) to 255 (transparent) 0 -1 to 1 (a > 0) ? (old_a+a*(255-old_a)) : (old_a+a*old_a) Alpha-channel (transparency).
B (brightness) 0 to 255 0 -1 to 1 (b > 0) ? (old_b+b*(255-old_b)) : (old_b+b*old_b) Brightness (luminocity).
C (color) 0 to 255 0 any old_c + c Color (hue).
H (image height) 1 to 1000 500 N/A in rules. Valid in initial assignments only. Max. image height in pixels.
N (nesting) > 0 200 N/A in rules. Valid in initial assignments only. Maximum level of recursion.
R (rotation) 0 to 360 0 any old_r + r Rotation in degrees.
S (size) > 0 10 > 0 old_s * s Shape size.
T (saturation) 0 to 255 0 any old_t + t Color saturation.
W (image width) 1 to 1000 500 N/A in rules. Valid in initial assignments only. Max. image width in pixels.
X (x-coord) 0 to image width depends on scaling any old_x + s*(x*cos(r)-y*sin(r)) Horisontal shift.
Y (y-coord) 0 to image height depends on scaling any old_y + s*(y*cos(r)+x*sin(r)) Vertical shift.

Notes (under construction)


<< Back   Top