Fractal formula


Fractal construction
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:

  • Axiom: F
  • F → FGF
  • G → GGG
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:
  • F → A
  • F → B
  • F → C
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.


Figure construction
Principle

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

Available commands

  • +: 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 backward
  • S: skip, move but do not draw
  • J: jump, move but do not draw (alias for S)
Other uppercase letters (such as A, C, D, E, F, G...) will draw a line forward.
Lowercase letters will do nothing but will be replaced as usual.
  • Axiom: a
  • a → bF
  • b → aG
Will give:
  • Iteration 1: bF
  • Iteration 2: aGF
  • Iteration 3: bFGF
  • ...
At iteration 3, 3 lines will be drawn (FGF), b will be ignored.
More generally, any character can be redefined in rules, for example the following rule set will produce random angles:
  • + → +
  • + → ++
  • + → +++


Blockchain consideration
Blockchain storage

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
Where:
  • 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
The initial example can be stored using one of the following equivalent formula :
  • 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)