Skip to content

evanlindsey/rustbonsai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

rustbonsai

A Rust port of cbonsai โ€” a beautifully random bonsai tree generator for your terminal.

This is a faithful reimplementation of the C/ncurses original, built on crossterm instead of ncurses (so it runs on macOS, Linux, and Windows with no system curses dependency). The binary is named rustbonsai and accepts the same flags as upstream cbonsai.

Fidelity

The RNG is a reimplementation of glibc's random()/rand() (the TYPE_3 additive-feedback generator). This means a given --seed produces the same tree as the original cbonsai built against glibc:

rustbonsai -p -s 42   # identical layout to upstream `cbonsai -p -s 42` on glibc

The tree starts at the centre of the terminal and grows into the available space, so an exact match also requires the same terminal dimensions as the upstream run. The RNG match is verified by a unit test against glibc's known srand(1) output sequence (cargo test).

Build

cargo build --release
./target/release/rustbonsai

Install

cargo install --path .   # builds release and installs `rustbonsai` to ~/.cargo/bin

As long as ~/.cargo/bin is on your PATH, you can then run rustbonsai from anywhere. To remove it later: cargo uninstall rustbonsai.

Usage

Usage: rustbonsai [OPTION]...

  -l, --live             live mode: show each step of growth
  -t, --time=TIME        in live mode, seconds between growth steps [default: 0.03]
  -i, --infinite         infinite mode: keep growing trees
  -w, --wait=TIME        in infinite mode, seconds between trees [default: 4.00]
  -S, --screensaver      screensaver mode (-li, quit on any keypress)
  -m, --message=STR      attach a message next to the tree
  -b, --base=INT         ascii-art base to use (0 = none) [default: 1]
  -c, --leaf=LIST        comma-delimited strings chosen at random for leaves [default: &]
  -k, --color=LIST       4 comma-delimited color indices (0-255):
                           dark leaves, dark wood, light leaves, light wood [default: 2,3,10,11]
  -M, --multiplier=INT   branch multiplier; higher -> more branching (0-20) [default: 5]
  -L, --life=INT         life; higher -> more growth (0-200) [default: 32]
  -p, --print            print the finished tree to the terminal and exit
  -s, --seed=INT         seed the random number generator
  -W, --save=FILE        save progress (seed + branch count) to FILE
  -C, --load=FILE        load progress from FILE
  -v, --verbose          increase output verbosity
  -h, --help             show help

Press q to quit. In interactive (non-print) mode, press any key once the tree has finished growing.

Examples

rustbonsai                       # grow a tree, wait for a keypress
rustbonsai -l                    # watch it grow live
rustbonsai -li                   # live + infinite (a gentle screensaver)
rustbonsai -p -s 42              # print a reproducible tree and exit
rustbonsai -m "stay grounded"    # add a message
rustbonsai -c "๐Ÿƒ,๐ŸŒธ" -M 8       # custom leaves, denser branching

Layout

  • src/rng.rs โ€” glibc-compatible rand().
  • src/config.rs โ€” CLI parsing and defaults.
  • src/render.rs โ€” cell-grid screen buffer (diff-based draw + ANSI export).
  • src/main.rs โ€” the recursive branch-growth algorithm and main loop.

License & attribution

rustbonsai is licensed under the GNU General Public License v3.0 or later (see LICENSE).

It is a derivative work of cbonsai by John Allbritten, reusing its tree-growth algorithm, ASCII-art bases, help text, and command-line interface. cbonsai is also GPL-3.0-or-later; as a derivative, this port carries the same license. See NOTICE for full attribution.

About

๐ŸŒณ Rust port of cbonsai - A beautifully random bonsai tree generator for your terminal

Resources

License

Stars

Watchers

Forks

Contributors

Languages