Write a Fracta script and click Run
A lightweight domain-specific language to define, render, and explore fractals.
Fracta is a line-oriented plaintext DSL that expresses fractal geometry through three computational engines: L-systems (string-rewriting turtle graphics), PIXEL (escape-time complex-plane iteration), and IFS (Iterated Function Systems via affine transforms). Scripts are deterministic 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
ENGINE, AXIOM, RULE, …) must be UPPERCASE. Rule symbols are case-sensitive.# are ignored. Inline # is also a comment delimiter.Select the rendering engine with the ENGINE directive at the top of your script.
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.
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 (any matplotlib colormap), C_VAL (fixes c for Julia sets)
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: z (current iterate), c (parameter point or fixed constant), np (NumPy).
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
| Directive | Engines | Syntax | Description |
|---|---|---|---|
ENGINE | all | ENGINE L_SYSTEM | PIXEL | IFS | Selects the rendering backend. |
AXIOM | L_SYSTEM | AXIOM <string> | Seed string at iteration 0. |
RULE | L_SYSTEM / IFS | RULE <pred> -> <succ> | Production rule (L_SYSTEM) or affine transform row (IFS). |
ANGLE | L_SYSTEM | ANGLE <float> or ANGLE <float>r | Rotation step in degrees, or radians with r suffix. Positive = counterclockwise. |
ITER | all | ITER <int> | Recursion depth (L_SYSTEM), escape iterations (PIXEL), or random steps (IFS). |
FORMULA | PIXEL | FORMULA <expr> | Python expression in z, c, np. |
X_RANGE | PIXEL | X_RANGE <min> <max> | Real-axis bounds. |
Y_RANGE | PIXEL | Y_RANGE <min> <max> | Imaginary-axis bounds. |
RES | PIXEL | RES <int> | Grid resolution (pixels per side). |
C_VAL | PIXEL | C_VAL <real>+<imag>j | Fixed parameter for Julia sets. |
COLORMAP | PIXEL / GRID | COLORMAP <name> | Any matplotlib colormap name. |
RENDER | all | RENDER | Execute and render the fractal. |
RENDER_AS_GRID | L_SYSTEM | RENDER_AS_GRID | Render evolution as 2D cell grid (cellular automata mode). |
| Token | Action | State change |
|---|---|---|
F | Draw forward | x, y advance; line is drawn |
G | Draw forward (synonym) | Same as F; useful for dual-variable rules |
f | Move forward (pen up) | x, y advance; no line drawn |
+ | Rotate counterclockwise | θ′ = θ + ANGLE |
- | Rotate clockwise | θ′ = θ − ANGLE |
[ | Push state | Saves (x, y, θ) onto LIFO stack |
] | Pop state | Restores (x, y, θ) from stack |
| other | NOP | Placeholder 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.
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.
<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" )
<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> }
┌─────────────────────────────────────┐
│ 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 → 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.
ENGINE L_SYSTEM
AXIOM F--F--F
RULE F -> F+F--F+F
ANGLE 60
ITER 4
RENDER
ENGINE L_SYSTEM
AXIOM X
RULE X -> F+[[X]-X]-F[-FX]+X
RULE F -> FF
ANGLE 25
ITER 5
RENDER
ENGINE L_SYSTEM
AXIOM FX
RULE X -> X+YF+
RULE Y -> -FX-Y
ANGLE 90
ITER 12
RENDER
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
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
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