Crate knossos

source ·
Expand description

Overview

A simple library for generating mazes with some basic routines for rendering and saving mazes to files.

Installation

Run the following Cargo command in your project directory:

cargo add knossos

Or add the following line to your Cargo.toml:

[dependencies]
knossos = "0.4.0"

Usage

This crate is designed to be super easy to use. Here are some usage examples of how to generate, display and save mazes:

Generate with default parameters

use knossos::maze::*;

let maze = OrthogonalMazeBuilder::new().build();

Generate with custom parameters

use knossos::maze::*;

let maze = OrthogonalMazeBuilder::new()
 .height(10)
 .width(10)
 .algorithm(Box::new(GrowingTree::new(Method::Random)))
 .build();

Read more about maze builder API

Display

use knossos::maze::*;

let maze = OrthogonalMazeBuilder::new().build();
println!("{}", &maze);

Save to file

use knossos::maze::*;

let maze = OrthogonalMazeBuilder::new().build();

// Save as ascii
maze.save("output/maze.txt", AsciiNarrow).unwrap();
// Save as a game map
maze.save("output/maze_game_map.txt", GameMap::new().span(3)).unwrap();
// Save as a PNG image
maze.save("output/maze.png", Image::new().wall(10).passage(30)).unwrap();

Read more about maze formatters

Algorithms

You can find 10 different algorithms supported by this crate. Each of them has its own pros and cons: some of them are impressively efficient, some of them are slower but generate splendid mazes that look hard to puzzle out, and others are extremely flexible and customizable. Do give each of them a shot and find the best one that suits you:

Modules

  • Maze representations, builders, formatters, and supported algorithms for generating mazes

Enums

  • An enumeration over supported color types for filling a maze image with colors