Skip to content

art.generative

pictures grown from simple rules: fractals, cellular automata, the Game of Life, mazes, starfields

Pictures that grow from a few simple rules. Give a size and sometimes a seed, and get back a fractal, a cellular automaton, a Game of Life board, a maze or a starfield, drawn as text.

Tags: art

  • lsystem grow and draw an L-system
  • fractal draw a well-known fractal by name
  • rule run a cellular automaton
  • spiral an Ulam spiral: the numbers 1, 2, 3, … wound outward from the center, with a dot for each prime
  • starfield a random night sky
  • mandelbrot the Mandelbrot set, the famous fractal, drawn in ASCII characters
  • life run Conway’s Game of Life for steps generations and draw the live cells
  • maze a random maze with exactly one path between any two points
lsystem(axiom: str, rules: map, angle: num, n: int, width: int = 60) -> str

grow and draw an L-system

Start from the axiom string and rewrite it n times, replacing each character that has a rule (a map from a character to its replacement). Then draw the result in braille dots, width characters wide, with a pen that starts facing up: F and G draw a step, f moves a step without drawing, + and - turn by angle degrees, | turns around, [ saves the pen’s place and ] goes back to it. Other characters do nothing

1
lsystem("F", {F: "F+F-F-F+F"}, 90, 3, 30)
⡤⠇ ⣀⡏⣏⡇ ⢀⣀⣖⡃ ⢀⣰⠚ ⠓⣗⣆⣖⡆ ⢰⢺⢲ ⡖⡗⡗⡆ ⢠⠼⠉⠈⠉ ⠉⠁⠉⠁ ⡤⠏⠹⠽ ⣏⡁ ⠓⣆⣰⣲ ⠘⢲⣀⢀⣀ ⣀⡀⣀⡀ ⠸⢼⠼ ⠧⡧⡧⠇ ⠈⠹⢤ ⡤⡯⠏⠯⠇ ⠈⠉⠯⡅ ⠉⣇⣏⡇ ⠓⡆
Example outputCtrl+Enter to run

See also fractal

fractal(name: str, n?: int, width: int = 60) -> str / fractal() -> list

draw a well-known fractal by name

The names are “dragon”, “koch”, “hilbert”, “sierpinski”, “levy”, “gosper”, “tree”, “fern” and “bush”. n is how many times to rewrite, so higher is more detailed (each fractal has its own usual depth), and width is as for lsystem. With no name, the list of names

1
fractal("koch", 3, 30)
⡀⠠⡴⢧⠄⢀ ⠐⡞⠑⠚ ⠓⠊⢓⡆ ⣀⣠⣀ ⢈⣙⠄ ⠠⣋⡁ ⣀⣠⣀ ⣀⡴⣀⡕ ⢪⣀⢦⣀⠇ ⠐⣅⡴⣀⡕ ⢪⣀⢦⣀ ⠯⡄ ⢠⠽ ⢖⠋ ⠙⡲ ⠓⠲⠒⡢ ⢔⠒⠖⠚ ⣉⡧ ⠰⣉ ⡤⠴⠤⠕ ⠪⠤⠦⢤ ⠮⣄ ⣠⠵ ⣖⠃ ⠘⣲ ⠉⠳⠉⡣ ⢜⠉⠞⠉⡆ ⠠⡋⠳⠉⡣ ⢜⠉⠞⠉ ⠉⠙⠉ ⢈⣩⠂ ⠐⣍⡁ ⠉⠙⠉ ⠠⢧⡠⢤ ⡤⢄⡬⠇ ⠁⠐⠳⡞⠂⠈
2
fractal()["dragon", "koch", "hilbert", "sierpinski", "levy", "gosper", "tree", "fern", "bush"]
Example outputCtrl+Enter to run

See also lsystem, rule

rule(n: int, width: int = 64, steps?: int) -> str

run a cellular automaton

A row of cells, each on or off, where each new row follows from the one above by the rule numbered n (0-255). It starts from a single live cell in a row width cells wide whose ends wrap around. Draws steps rows (half the width without steps), two rows per line of text

1
rule(30, 32)
▄█▄ ▄█▀▄▄█▄ ▄█▀▄▄█▄ ▄█▄ ▄█▀▄▄█▄ ▄█▄▄█▄ ▄█▀▄▄█▄ ▄█▀▀▄ ▄█▄ ▄█▀▄▄█▄ ▄█ █▀▀▀ █▀▄▄█▄ ▄█▀▄▄█▄ ▄█▀▀▄▄█▀▄▄█▀ █▄ ▄█▄ ▄█▀▄▄█▄ ▄█ █▀▀▄ ▄█▄▄█▀▀▄▄█▄▄█▄
2
rule(90, 32, 16)
▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄
Example outputCtrl+Enter to run

See also life, fractal

spiral(size: int = 40) -> str

an Ulam spiral: the numbers 1, 2, 3, … wound outward from the center, with a dot for each prime

The primes mysteriously line up along diagonals. size characters wide

1
spiral(20)
⢀⠄⠁⢐⢄⠄⠐ ⠔⠑⠄⠕ ⢁ ⠁⢐ ⢀⠄ ⢀⠁⢁ ⠁⠔⠁⢔⢐ ⠐⢄⠁⠄⠄⠁ ⠐⠑⢄⠁⢁⠄ ⠕⠁⢀ ⢅⢀⠐⢅⢐⢀ ⠐⠐ ⢀⠁⢁⠐⢀ ⢑⢀⠐⢑⠄⠄ ⢀⠅⢁⢄⠑⠄⠄ ⠐⠄⠄⠄⠔⠄⠔⠔⢄⢁⢕⠐⠑ ⠄⠐⢐⠐ ⢀⠐⢀⢀ ⢑⢔⠑⢌⠁⢁⢁⠁⢀⠁⢁⢁ ⢀⢅ ⢁ ⢅⠄⠑ ⠄⠁⢄ ⠕⠁⢀⠁⠄⢄ ⠅⢄⠄⢅ ⠐⠑ ⠕⢅⢀⠐⠄⠐ ⠄⠔ ⠑⠐⠁⠁⢀⠐⢅⠄ ⢅⠔⠁⢁ ⠐⠄ ⢐⢅ ⢐ ⢐⢀⠁⢁⠐ ⢁ ⠐ ⢐⠄ ⠑⠄
Example outputCtrl+Enter to run

See also is_prime

starfield(width: int, height: int, seed?: int) -> str

a random night sky

Give the same seed to get the same sky again

1
starfield(30, 4, 7)
. · · · · + + . ·
Example outputCtrl+Enter to run

See also negative

mandelbrot(width: int = 72, height: int = 24) -> str

the Mandelbrot set, the famous fractal, drawn in ASCII characters

1
mandelbrot(40, 12)
...: ...:@@@.. ..#+=@@@@@@@:#:. .........#@@@@@@@@@@@@-. ..:@@@@@:@@@@@@@@@@@@@@@- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-.. ..:@@@@@:@@@@@@@@@@@@@@@- .........#@@@@@@@@@@@@-. ..#+=@@@@@@@:#:. ...:@@@.. ...:
Example outputCtrl+Enter to run

See also life

life(start: str, steps: int = 1, wrap: bool = false) -> str

run Conway’s Game of Life for steps generations and draw the live cells

On a grid, a live cell survives with 2 or 3 live neighbours, and an empty cell comes alive with exactly 3. start is a picture with # for live cells and . for empty ones, or a named pattern: “glider”, “blinker”, “pulsar” or “r_pentomino”. The board grows as needed, unless wrap is true: then it stays start’s size and cells leaving one edge come back on the other

1
life("blinker")
# # #
2
life("glider", 4)
.#. ..# ###
Example outputCtrl+Enter to run

See also maze

maze(width: int = 20, height: int = 10) -> str

a random maze with exactly one path between any two points

1
maze(6, 3)
██ ██████████████████████ ██ ██ ██ ██████████ ██ ██████████ ██ ██ ██ ██ ██████████████████ ██ ██ ██ ██████████████████████ ██
Example outputCtrl+Enter to run

See also life

1
# a dragon curve
2
fractal("dragon", 8, 30)
⣀⣸⣉⡇ ⢀⣸⣉⡇ ⠓⢺⠒⡆⡖⢺⢺⠒⡆⡖⠂ ⠸⠭⡧⠏⠹⢤ ⢠⢤ ⠯⢽⠭⡯⡅⠈⠉ ⠉⠯⠅ ⣖⣲⣰⣒⡃ ⠐⠚ ⣖⣺⣚ ⣀⣖⣚ ⠓⠃ ⣆⡖⠂ ⠸⢼⠤⠇ ⡤⢼⢼⠤⡧⡧⢼⠤⡄ ⣀⣀⢘⣒⣆⣖⣲ ⣀⣰⣲ ⣓⣺⣺⣒⣗⣗⣺⠒⣗⡆ ⠧⢼⢼⠤⡧⡧⢤⢠⠤⡧⢼⢤ ⡤⡧⢼⢼⠤⡧⡧⢤ ⠈⠉ ⠉⠁⠈⢹⣉⣏⣹⣹⣉⡁⠉⠉⠈⠉⣏⣏⣹⣉⣇⡀ ⡖⢲⢰⠒⡗⠚⠘⠒⠃ ⢰⢲ ⡖⡗⠚ ⠓⠃ ⠉⠹⠽⠉⠯⠽ ⠈⠹⠭⠏⠯⠽
3
# a tree in a box
4
fractal("tree", 6, 24).boxed("round")
╭───────────────────╮ │ ⢀⡀⠐⢾ ⡯⠂ ⠐⠪⡇⡹⠒ ⣀ │ │ ⣀⠓⣇ ⢹ ⢹⠁ ⢀⠗⢃ │ │ ⠞⠉⠉⠑⠤⣸ ⢸⡠⠔⠉⠉⠱ │ │ ⠘⢆ ⢀⠎ │ │ ⠈⢢ ⣠⠃ │ │ ⢳⠃ │ │ ⢸ │ │ ⢸ │ │ ⢸ │ │ ⢸ │ │ ⢸ │ │ ⢸ │ ╰───────────────────╯
5
# Sierpinski's triangle, two ways
6
rule(90, 32, 16).beside(fractal("sierpinski", 4, 16), 4)
▄▀▄ ⣰⣇ ▄▀▄ ▄▀▄ ⣼⣷⣾⣧ ▄▀▄ ▄▀▄ ⢀⡾⢿⡄⢠⡿⢷⡀ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ⢠⣞⠛⠚⠛⠛⠓⠛⣳⡄ ▄▀▄ ▄▀▄ ⣠⣿⣻⣦ ⣴⣟⣿⣄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ⣰⣯⡉⠉⣹⣧⡀⢀⣼⣏⠉⢉⣽⣆ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ⠼⠷⠼⠷⠼⠷⠼⠷⠾⠧⠾⠧⠾⠧⠾⠧ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄ ▄▀▄
7
# a plant from your own rules
8
lsystem("X", {X: "F[-X][X]F[-X]+FX", F: "FF"}, 25, 4, 30)
⣀⡀⠐⣄⡀ ⠈⢧ ⡄ ⠈⠉⠙⠳⡀ ⠈⢷⡇ ⠒⡄⢀ ⠈⠲⣄⢻⢆⣜ ⠸⣸ ⠹⣿⠎ ⡟ ⢰ ⡀⠹⣀ ⠢⡌⣇ ⢠⣏⡄ ⠉⠓⢵⣇ ⠠⡸⣿⣜⠟⡉ ⢻ ⣷⣿⡿⠊⢱ ⠈⢣ ⣬⡿⡇ ⢠⣏⡀ ⢣⡇⣧⣏⣼⡟⠋ ⢸⡝⢺⣵⣿⠖⠁ ⢸⢠⠋ ⢸⠃ ⢸ ⢸ ⢸
9
# the Mandelbrot set
10
mandelbrot()
.-. ....... ...-=:... .....:@@@@@:.. .........:@@@@+:......... ....:@@:%@@@@@@@@@@@@@:.:::#. .....*.#@@@@@@@@@@@@@@@@@@@@@:.. ................-@@@@@@@@@@@@@@@@@@@@@@@=... ....:@-.:@::...:=@@@@@@@@@@@@@@@@@@@@@@@@@-.. ...:.-@@@@@@@@=:-@@@@@@@@@@@@@@@@@@@@@@@@@@@-. ........#=:+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+:... ........#=:+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ...:.-@@@@@@@@=:-@@@@@@@@@@@@@@@@@@@@@@@@@@@-. ....:@-.:@::...:=@@@@@@@@@@@@@@@@@@@@@@@@@-.. ................-@@@@@@@@@@@@@@@@@@@@@@@=... .....*.#@@@@@@@@@@@@@@@@@@@@@:.. ....:@@:%@@@@@@@@@@@@@:.:::#. .........:@@@@+:......... .....:@@@@@:.. ...-=:... ....... .-.
11
# a glider, 8 steps on
12
life("glider", 8)
.#. ..# ###
13
# start from your own pattern
14
life(".#.\n.#.\n.#.", 1)"###"
15
# a maze
16
maze(12, 6)
██ ██████████████████████████████████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████████ ██ ██████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████████████████████ ██ ██████████ ██ ██ ██ ██ ██ ██ ██████████ ██████ ██ ██ ██████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ██ ██████████ ██ ██████████████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ██ ██ ██████████████████████ ██ ██ ██ ██ ██ ██████████████████████████████████████████████ ██
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.