Universe

Create a variety of wonderful fractals and curves in Typst.

Examples

Dragon Curve Koch Snowflake Sierpiński Triangle
Hypotrochoid Random Fractal Tree Pythagorean Tree

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.
  • Generate various parameterized fractal trees.
  • Generate Fibonacci word fractals.

Usage

Import the latest version of this package with:

#import "@preview/fractusist:0.2.1": *

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) = {...}

Tree

  • fractal-tree: Generate fractal tree (n: integer range [1, 14])
#let fractal-tree(n, root-color: rgb("#46230A"), leaf-color: rgb("#228B22"), trunk-len: 100, trunk-rad: 3.0, theta: 1/2, angle: 1/4, ratio: 0.8) = {...}
  • random-fractal-tree: Generate random fractal tree (n: integer range [1, 14])
#let random-fractal-tree(n, seed: 42, root-color: rgb("#46230A"), leaf-color: rgb("#228B22"), trunk-len: 100, trunk-rad: 3.0, theta: 1/2, angle: 1/4, ratio: 0.8) = {...}
  • pythagorean-tree: Generate Pythagorean tree (n: integer range [1, 14])
#let pythagorean-tree(n, root-color: rgb("#46230A"), leaf-color: rgb("#228B22"), trunk-len: 50, theta: 1/5, filling: true) = {...}

Fibonacci

  • fibonacci-word-fractal: Generate Fibonacci word fractal (n: integer range [3, 24])
#let fibonacci-word-fractal(n, skip-last: true, step-size: 10, start-dir: 0, stroke: black + 1pt) = {...}