Principle
An initial figure (named axiom) is used as a first step.
Then, some rules are used to define how parts of the current step will be replaced by other figures to produce the next step.
Example
- Angle: 90°
- Axiom:
- Rule: replace each line by
Will give:
- Iteration 0 (axiom):
- Iteration 1:
- Iteration 2:
- Iteration 3:
Figure definition
Figures are defined using a simple language, that will tell the pencil how to move, rotate or draw a line.
Axiom of the previous example can be defined by F+F+F+F, i.e. draw a line forward then rotate 90° then draw a line forward then rotate 90° then draw a line forward then rotate 90° then draw a line forward. Giving a square.
At each iteration, every F will be replaced by the figure given in the rule, in this example: F-F+F+F-F:
- Angle: 90°
- Axiom: F+F+F+F
- Rule: F → F-F+F+F-F
Will give:
- Iteration 0 (axiom): F+F+F+F
- Iteration 1: F-F+F+F-F+F-F+F+F-F+F-F+F+F-F+F-F+F+F-F
- Iteration 2: F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F
- ...
Multiple rules
It is possible to have multiple rules, for example:
It will work as expected:
- Iteration 1: FGF
- Iteration 2: FGFGGGFGF
- Iteration 3: FGFGGGFGFGGGGGGGGGFGFGGGFGF
- ...
It is even possible to have several rules for the same character:
One of the rules will be selected in an uniformly randomly way (33% in this case).
A pseudo random number generator is used, with a seed that depends exclusively on the token identifier.
Parameters
When creating a fractal, the following parameters should be provided:
- The angle, in degree. Required by the + and - commands.
- The angle step, in degree. Only required if { and } commands are used.
- The length divisor. Only required if [ and ] commands are used.
- The axiom.
- The rules.
- The number of iteration to compute.