Create a variety of wonderful fractals and curves in Typst.
Examples
![]() | ![]() |
Dragon Curve | Koch Snowflake |
![]() | ![]() |
Sierpiński Triangle | Hypotrochoid |
Click on the example image to jump to the code.
Features
- Generate fractals using L-system.
- The number of iterations, step size, fill and stroke styles, etc. of generated fractals could be customized.
- Generate spirograph and Lissajous curves with various parameters.
Usage
Import the latest version of this package with:
#import "@preview/fractusist:0.2.0": *
Each function (see reference) generates a specific curve. The shape and size of it is configurable. And the fill and stroke style arguments are equivalent to those in the curve
function. The returned graph is contained within the box
element.
This package comes with some unit tests under the tests directory.
Reference
Dragon
dragon-curve
: Generate dragon curve (n: integer range [0, 16]).
#let dragon-curve(n, step-size: 10, stroke: black + 1pt) = {...}
Hilbert
hilbert-curve
: Generate 2D Hilbert curve. (n: integer range [1, 8]).
#let hilbert-curve(n, step-size: 10, stroke: black + 1pt) = {...}
peano-curve
: Generate 2D Peano curve (n: integer range [1, 5]).
#let peano-curve(n, step-size: 10, stroke: black + 1pt) = {...}
Koch
koch-curve
: Generate Koch curve (n: integer range [0, 6]).
#let koch-curve(n, step-size: 10, fill: none, stroke: black + 1pt) = {...}
koch-snowflake
: Generate Koch snowflake (n: integer range [0, 6]).
#let koch-snowflake(n, step-size: 10, fill: none, stroke: black + 1pt) = {...}
Sierpiński
sierpinski-curve
: Generate classic Sierpiński curve (n: integer range [0, 7]).
#let sierpinski-curve(n, step-size: 10, fill: none, stroke: black + 1pt) = {...}
sierpinski-square-curve
: Generate Sierpiński square curve (n: integer range [0, 7]).
#let sierpinski-square-curve(n, step-size: 10, fill: none, stroke: black + 1pt) = {...}
sierpinski-arrowhead-curve
: Generate Sierpiński arrowhead curve (n: integer range [0, 8]).
#let sierpinski-arrowhead-curve(n, step-size: 10, stroke: black + 1pt) = {...}
sierpinski-triangle
: Generate 2D Sierpiński triangle (n: integer range [0, 6]).
#let sierpinski-triangle(n, step-size: 10, fill: none, stroke: black + 1pt) = {...}
Spirograph
hypotrochoid
: Generate hypotrochoid (a, b, h: integer range [1, 100]).
#let hypotrochoid(a, b, h, size: 100, fill: none, fill-rule: "non-zero", stroke: black + 1pt) = {...}
epitrochoid
: Generate epitrochoid (a, b, h: integer range [1, 100]).
#let epitrochoid(a, b, h, size: 100, fill: none, fill-rule: "non-zero", stroke: black + 1pt) = {...}
Lissajous
lissajous-curve
: Generate Lissajous curve (a, b: integer range [1, 100], d: float range [0, 2]).
#let lissajous-curve(a, b, d, x-size: 100, y-size: 100, fill: none, fill-rule: "non-zero", stroke: black + 1pt) = {...}