Fractal construction

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.

- Angle: 90°
- Axiom:
- Rule: replace each line by

- Iteration 0 (axiom):
- Iteration 1:
- Iteration 2:
- Iteration 3:

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

- 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
- ...

It is possible to have multiple rules, for example:

- Axiom: F
- F → FGF
- G → GGG

- Iteration 1: FGF
- Iteration 2: FGFGGGFGF
- Iteration 3: FGFGGGFGFGGGGGGGGGFGFGGGFGF
- ...

- F → A
- F → B
- F → C

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.

Figure construction

Figures are drawn using a string of characters that have a specific meaning.

- +: rotate clockwise of current angle
- -: rotate counter-clockwise of current angle
- [: divide line length by the length divisor
- ]: multiply line length by the length divisor
- {: decrease current angle of angle step
- }: increase current angle of angle step
- 0: use color 0 for next lines
- 1: use color 1 for next lines
- 2: use color 2 for next lines
- 3: use color 3 for next lines
- 4: use color 4 for next lines
- 5: use color 5 for next lines
- 6: use color 6 for next lines
- <: use next color
- >: use previous color
- (: save current angle and position on stack
- ): restore angle and position from stack
- B: draw a line
__b__ackward - S:
__s__kip, move but do not draw - J:
__j__ump, move but do not draw (alias for S)

Lowercase letters will do nothing but will be replaced as usual.

- Axiom: a
- a → bF
- b → aG

- Iteration 1: bF
- Iteration 2: aGF
- Iteration 3: bFGF
- ...

More generally, any character can be redefined in rules, for example the following rule set will produce random angles:

- + → +
- + → ++
- + → +++

Blockchain consideration

Inside the blockchain, formula is stored using a character string that comply with one of the following format:

- Axiom;Rules;Iterations
- Angle;Axiom;Rules;Iterations
- Angle;Angle step;Axiom;Rules;Iterations
- Angle;Angle step;Length divisor;Axiom;Rules;Iterations

- Axiom is a string like F+F+F+F using the available commands
- Rules is a string like F-F+F+F-F (equivalent to F:F-F+F+F-F), F:FGF,G:GGG, ...
- Angle and angle step are in degree * 1000, example 90000 for 90°. If ommitted, angle is and angle step is .
- Length divisor is * 100, 200 meaning that [ will divide length by 2, 180 by 1.8 on so on. If omitted, length divisor is

- F+F+F+F;F-F+F+F-F;4
- F+F+F+F;F:F-F+F+F-F;4
- A+A+A+A;A:A-A+A+A-A;4
- 90000;F+F+F+F;F:F-F+F+F-F;4
- 90000;22500;200;F+F+F+F;F:F-F+F+F-F;4 (angle step and length divisor are not used here)