Editor
Initializing Python runtime…
Output

Write a Fracta script and click Run

fractal output

FRACTA

A lightweight domain-specific language to define, render, and explore fractals.

1. Overview

Fracta is a line-oriented plaintext DSL that expresses fractal geometry through four computational engines: L-systems (string-rewriting turtle graphics), PIXEL (escape-time complex-plane iteration), IFS (Iterated Function Systems via affine transforms), and REACTION_DIFFUSION (Gray-Scott continuous reaction-diffusion simulation). Scripts are deterministic — except for the stochastic seed in REACTION_DIFFUSION — and portable across any conforming interpreter.

A minimal Fracta program selects an engine, sets parameters, and issues RENDER:

ENGINE L_SYSTEM
AXIOM F--F--F
RULE F -> F+F--F+F
ANGLE 60
ITER 4
RENDER

2. Lexical Rules

3. Engines

Select the rendering engine with the ENGINE directive at the top of your script.

L_SYSTEM   Lindenmayer String-Rewriting

Applies production rules to a seed string (axiom) iteratively, then interprets the result as turtle-graphics commands. Produces curves, trees, snowflakes, and space-filling patterns.

Required: AXIOM, RULE (one or more), ANGLE, ITER

ENGINE L_SYSTEM
AXIOM FX
RULE X -> X+YF+
RULE Y -> -FX-Y
ANGLE 90
ITER 12
RENDER

Use RENDER_AS_GRID instead of RENDER to visualize 1D cellular automaton evolution as a 2D grid. In grid mode RULE uses context syntax: RULE center > right -> output.

PIXEL   Escape-Time Complex Iteration

Evaluates a complex formula on a grid of points, counting how many iterations before |z| > 2 (escape time). Classic Mandelbrot, Julia, Burning Ship, and custom formulas.

Required: FORMULA, X_RANGE, Y_RANGE, RES, ITER

Optional: COLORMAP, C_VAL (fixes c for Julia sets), PARAM name value (named constant), STEP lhs = rhs (intermediate assignment per iteration), BAILOUT expr (custom escape condition, default np.abs(z) <= 2.0)

ENGINE PIXEL
FORMULA z**2 + c
X_RANGE -2.0 0.5
Y_RANGE -1.25 1.25
RES 600
ITER 100
COLORMAP magma
RENDER

Variables available in FORMULA and STEP: z (current iterate), c (parameter point or fixed constant), np (NumPy), plus any names defined by PARAM.

IFS   Iterated Function System

Randomly applies affine transformations with given probabilities. Each rule encodes prob, a, b, c, d, e, f where the transform is x' = ax + by + e, y' = cx + dy + f.

Required: RULE (one or more with 7 space-separated floats), ITER (number of random steps)

ENGINE IFS
ITER 80000
RULE 0.01  0.0   0.0   0.0   0.16  0.0  0.0
RULE 0.85  0.85  0.04 -0.04  0.85  0.0  1.6
RULE 0.07  0.2  -0.26  0.23  0.22  0.0  1.6
RULE 0.07 -0.15  0.28  0.26  0.24  0.0  0.44
RENDER

REACTION_DIFFUSION   Gray-Scott Continuous Simulation

Simulates two chemical species U and V on a 2D grid using the Gray-Scott model. Depending on the feed rate f and kill rate k, emergent Turing patterns appear: spots, mazes, stripes, spirals, or coral-like structures.

Optional: RES (grid size, default 128, capped at 200), STEPS (simulation steps, default 2000, capped at 5000), FEED, KILL, DU, DV, COLORMAP

ENGINE REACTION_DIFFUSION
RES 128
STEPS 3000
FEED 0.035
KILL 0.065
COLORMAP inferno
RENDER

The simulation initialises U≈1 everywhere and seeds a central square with V≈0.25. Pattern type depends heavily on the (f, k) pair — see the Phase Space section in the Examples below.

4. Directive Reference

DirectiveEnginesSyntaxDescription
ENGINEallENGINE L_SYSTEM | PIXEL | IFS | REACTION_DIFFUSIONSelects the rendering backend.
AXIOML_SYSTEMAXIOM <string>Seed string at iteration 0.
RULEL_SYSTEM / IFSRULE <pred> -> <succ>Production rule (L_SYSTEM) or affine transform row (IFS).
ANGLEL_SYSTEMANGLE <float> or ANGLE <float>rRotation step in degrees, or radians with r suffix. Positive = counterclockwise.
ITERallITER <int>Recursion depth (L_SYSTEM), escape iterations (PIXEL), or random steps (IFS).
FORMULAPIXELFORMULA <expr>Python expression in z, c, np.
X_RANGEPIXELX_RANGE <min> <max>Real-axis bounds.
Y_RANGEPIXELY_RANGE <min> <max>Imaginary-axis bounds.
RESPIXELRES <int>Grid resolution (pixels per side).
C_VALPIXELC_VAL <real>+<imag>jFixed parameter for Julia sets.
PARAMPIXELPARAM name valueNamed constant (complex or real); available in FORMULA, STEP, and BAILOUT.
STEPPIXELSTEP lhs = rhsOrdered intermediate assignment evaluated on the full grid each iteration (before FORMULA). Enables multi-statement loops.
BAILOUTPIXELBAILOUT exprCustom escape condition (boolean array); default is np.abs(z) <= 2.0.
COLORMAPPIXEL / GRIDCOLORMAP <name>Any matplotlib colormap name.
STEPSREACTION_DIFFUSIONSTEPS <int>Number of simulation time steps (default 2000, capped at 5000).
FEEDREACTION_DIFFUSIONFEED <float>Feed rate f for species U (default 0.055). Controls pattern type.
KILLREACTION_DIFFUSIONKILL <float>Kill rate k for species V (default 0.062). Controls pattern type.
DUREACTION_DIFFUSIONDU <float>Diffusion coefficient for U (default 0.16).
DVREACTION_DIFFUSIONDV <float>Diffusion coefficient for V (default 0.08).
RENDERallRENDERExecute and render the fractal.
RENDER_AS_GRIDL_SYSTEMRENDER_AS_GRIDRender evolution as 2D cell grid (cellular automata mode).

5. Turtle Graphics Alphabet (L_SYSTEM)

TokenActionState change
FDraw forwardx, y advance; line is drawn
GDraw forward (synonym)Same as F; useful for dual-variable rules
fMove forward (pen up)x, y advance; no line drawn
+Rotate counterclockwiseθ′ = θ + ANGLE
-Rotate clockwiseθ′ = θ − ANGLE
[Push stateSaves (x, y, θ) onto LIFO stack
]Pop stateRestores (x, y, θ) from stack
otherNOPPlaceholder only (e.g. X, Y for substitution)

The turtle starts at (0, 0) heading 90° (straight up). Angles follow the standard radial (anticlockwise-positive) convention.

6. ANGLE — Degrees vs Radians

By default ANGLE accepts degrees:

ANGLE 60       # 60 degrees

Append r to supply radians directly:

ANGLE 1.0472r  # π/3 ≈ 60°
ANGLE 3.14159r # π = 180°

Both formats follow the counterclockwise-positive convention: + increases θ, - decreases it.

7. Formal Grammar (EBNF)

<fracta_script> ::= { <statement> <newline> } ( <render_cmd> | <render_grid_cmd> )
<statement>     ::= <comment> | <engine_def> | <axiom_def> | <rule_def>
                  | <angle_def> | <iter_def> | <param_def>

<engine_def>    ::= "ENGINE " ( "L_SYSTEM" | "PIXEL" | "IFS" | "REACTION_DIFFUSION" )
<axiom_def>     ::= "AXIOM " <string_payload>
<rule_def>      ::= "RULE " <char_token> " -> " <string_payload>
<angle_def>     ::= "ANGLE " <float_val> [ "r" ]
<iter_def>      ::= "ITER " <int_val>
<param_def>     ::= <upper_ident> " " <value_string>
<render_cmd>    ::= "RENDER"
<render_grid_cmd> ::= "RENDER_AS_GRID"

<float_val>     ::= [0-9]+ [ "." [0-9]+ ]
<int_val>       ::= [0-9]+
<comment>       ::= "#" { <any_char> }

8. Runtime Pipeline

┌─────────────────────────────────────┐
│ 1. Lexical Scanner                  │
│    Lines → directives → param map  │
└────────────────┬────────────────────┘
                 │
                 ▼
┌─────────────────────────────────────┐
│ 2. Production Expansion (L_SYSTEM)  │
│    Axiom → apply rules × ITER       │
└────────────────┬────────────────────┘
                 │
                 ▼
┌─────────────────────────────────────┐
│ 3. Render                           │
│    Turtle trajectory / PIXEL grid / │
│    IFS random walk /                │
│    Gray-Scott RD → matplotlib       │
└─────────────────────────────────────┘

State vector during phase 3: S = ⟨x, y, θ, Stack⟩ where θ is initialized to 90° and Stack is a LIFO of (x, y, θ) triples. Unmatched ] tokens raise a runtime error.

9. Examples

Koch Snowflake

ENGINE L_SYSTEM
AXIOM F--F--F
RULE F -> F+F--F+F
ANGLE 60
ITER 4
RENDER

Fractal Plant

ENGINE L_SYSTEM
AXIOM X
RULE X -> F+[[X]-X]-F[-FX]+X
RULE F -> FF
ANGLE 25
ITER 5
RENDER

Heighway Dragon

ENGINE L_SYSTEM
AXIOM FX
RULE X -> X+YF+
RULE Y -> -FX-Y
ANGLE 90
ITER 12
RENDER

Mandelbrot Set

ENGINE PIXEL
FORMULA z**2 + c
X_RANGE -2.0 0.5
Y_RANGE -1.25 1.25
RES 600
ITER 100
COLORMAP magma
RENDER

Julia Set (c = −0.7 + 0.27i)

ENGINE PIXEL
FORMULA z**2 + c
C_VAL -0.7+0.27j
X_RANGE -1.5 1.5
Y_RANGE -1.5 1.5
RES 500
ITER 80
COLORMAP twilight_shifted
RENDER

Barnsley Fern (IFS)

ENGINE IFS
ITER 80000
RULE 0.01  0.0   0.0   0.0   0.16  0.0  0.0
RULE 0.85  0.85  0.04 -0.04  0.85  0.0  1.6
RULE 0.07  0.2  -0.26  0.23  0.22  0.0  1.6
RULE 0.07 -0.15  0.28  0.26  0.24  0.0  0.44
RENDER

10. Reaction-Diffusion Pattern Guide

The Gray-Scott model produces qualitatively different Turing patterns depending on the (FEED, KILL) pair. Small changes in these values can flip the simulation from spots to stripes to coral mazes.

PatternFEEDKILLNotes
Spots (Turing)0.0350.065Isolated circular spots on a uniform background
Coral / Maze0.0550.062Meandering labyrinthine channels
Zebrafish Stripes0.0220.051Parallel stripe domains
Moving Spots0.0250.060Self-replicating drifting spots
Worms0.0460.063Elongated worm-like domains

Gray-Scott — Turing Spots

ENGINE REACTION_DIFFUSION
RES 128
STEPS 3000
FEED 0.035
KILL 0.065
DU 0.16
DV 0.08
COLORMAP inferno
RENDER

Gray-Scott — Coral Maze

ENGINE REACTION_DIFFUSION
RES 128
STEPS 3000
FEED 0.055
KILL 0.062
DU 0.16
DV 0.08
COLORMAP RdYlBu
RENDER

Gray-Scott — Zebrafish Stripes

ENGINE REACTION_DIFFUSION
RES 128
STEPS 3500
FEED 0.022
KILL 0.051
DU 0.16
DV 0.08
COLORMAP viridis
RENDER

11. The .fct File Format

Fracta scripts are saved as plain UTF-8 text files with the .fct extension. A .fct file contains exactly one Fracta program — one ENGINE block ending with RENDER or RENDER_AS_GRID.

Specification

Canonical Layout

# Optional header comment — name, author, date
ENGINE <engine>
# Parameters
<KEY> <value>
RULE <...>
RENDER

Differences from .ufm (UltraFractal)

Feature.fct (Fracta).ufm (UltraFractal)
EnginesL_SYSTEM, PIXEL, IFS, REACTION_DIFFUSIONEscape-time formula only
Formula syntaxPython/NumPy expressionC-like DSL with #pixel, ^
ColoringIteration count + matplotlib colormapSeparate .ucl coloring formula
ParametersInline directives, no user paramsparam blocks (runtime sliders)
BailoutFixed: |z| ≤ 2.0User-defined expression
Multi-layerNot supportedSupported via .upr
L-systems / IFS / RDNative enginesNot in .ufm scope

Use ufm_to_fracta.py (or the Import UFM button in the playground) to convert UltraFractal .ufm escape-time formulas to .fct scripts. Unsupported UF features (multi-statement loops, custom bailout, user parameters, coloring algorithms) are reported as warnings.