Skip to content

Commit

Permalink
- Continued to expand the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aPixelInSpace committed Mar 17, 2021
1 parent 4054b5a commit 0d35f29
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 177 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ An easy-to-use, composable and configurable maze generator and solver. Several t
## Usage
You may visit https://mazes.apixelinspace.com to randomly generate a few examples (website in preview version, work in progress)

The CLI and the documentation are coming soon : https://apixelinspace.github.io/F-a-maze-ing/.
The CLI and the documentation are coming soon : https://github.com/aPixelInSpace/F-a-maze-ing/wiki.

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
theme: jekyll-theme-tactile
theme: jekyll-theme-architect
159 changes: 1 addition & 158 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,158 +1 @@
# Table of contents

- [Table of contents](#table-of-contents)
- [Usage](#usage)
- [Command Line Interface](#command-line-interface)
- [Canvas](#canvas)
- [s-rectangle](#s-rectangle)
- [s-triangle](#s-triangle)
- [s-ellipse](#s-ellipse)
- [s-hexagon](#s-hexagon)
- [s-pentagon](#s-pentagon)
- [s-pentagonStar](#s-pentagonstar)
- [s-image](#s-image)
- [Website](#website)

# Usage

## Command Line Interface

To use the CLI you first need to download [the app](https://github.com/aPixelInSpace/F-a-maze-ing) and to have on your computer the [.Net Core 5 runtime](https://dotnet.microsoft.com/download).

The CLI is designed to be composable with a maximum of options on each step to create unique and beautiful mazes.

The basic idea is to *pipe* different actions to generate and visualize, in the end, a maze.

The actions are :

1. Choosing a canvas
2. Choosing a type of grid
3. Choosing a maze generator algorithm
4. Choosing a render
5. Choosing an output

For example, the following line will generate a text maze in a file :

```
.\Mazes.exe s-rectangle -r 6 -c 10 : g-ortho : a-hk -s 1 : rt-ortho : o-file -p "./test.txt"
```

Each part is separated by a '**:**' wich is used as the pipe symbol.

Let's break it down :

- **.\Mazes.exe** is the path to the CLI itself
- **s-rectangle -r 6 -c 10** use a rectangle shape with 6 rows and 10 columns
- **g-ortho** use an orthogonal grid type
- **a-hk -s 1** use the "Hunt and Kill" algorithm with a random seed of 1 to generare the maze
- **rt-ortho** use the text unicode render
- **o-file -p "./test.txt"** save on the disk into the specified file

The result might look like this :

```
━┯━━━━━┯━━━━━┯━━━━━┓
┳ ┴ ╭─╴ │ ┬ ╶─╯ ┬ ┬ ┃
┠───╯ ╶─┴─┴─┬─╴ │ │ ┃
┃ ╶─╮ ╭───╴ ┴ ╭─┴─╯ ┃
┠───┤ │ ╭───┬─┴─┬─╴ ┃
┃ ┬ ┴ │ ┴ ┬ ╰─╴ │ ╶─┚
┗━┷━━━┷━━━┷━━━━━┷━━━
```

There are a number of actions available for each step. Note that *not* every combination will yield a valid maze.

It is possible to get every option for a given action by using ``--help`` so for example ``s-rectangle --help``

### Canvas

There are two types of canvas : Array2d and ArrayOfA.

Array2d canvas cannot be used on polar maze, only ArrayOfA canvas can be used for a polar maze.

#### s-rectangle

- Array2d type

```
-r, --rows Required. The number of rows.
-c, --columns Required. The number of columns.
```

#### s-triangle

- Array2d type

```
-b, --base Required. The length of the base.
--baseat (Default: 0) The position of the base Bottom, Top, Left or Right.
--basedecrement (Default: 1) The decrement value for the base.
```

#### s-ellipse

- Array2d type

```
-r, --rowRadiusLength Required. The length for the horizontal radius.
-c, --columnRadiusLength Required. The length for the vertical radius.
--rowenlargingfactor (Default: 0) Zoom factor on the horizontal axis.
--columnenlargingfactor (Default: 0) Zoom factor on the vertical axis.
--rowtranslationfactor (Default: 0) Translation factor on the horizontal axis.
--columntranslationfactor (Default: 0) Translation factor on the vertical axis.
--ellipsefactor (Default: 0) Inside ellipse factor.
--side (Default: 0) Indicate where the ellipse is Inside or Outside.
```

#### s-hexagon

- Array2d type

```
-s, --edgeSize Required. The length of one side of the hexagon.
```

#### s-pentagon

- Array2d type

```
-s, --edgeSize Required. The length of one side of the pentagon.
```

#### s-pentagonStar

- Array2d type

```
-g, --greatEdgeSize Required. The length of the great side of the pentagon star.
-s, --smallEdgeSize Required. The length of the small side of the pentagon star.
```

#### s-image

- Array2d type

Get a canvas/shape from an image. It works on the levels of black (with a parametrable tolerance) on each pixel.


```
-p, --path Required. The full path of the image file
-t, --tolerance (Default: 0) The tolerance on the pixel color.
```

## Website

A website is available [here](http://mazes.apixelinspace.com/) which is in preview version and where it is possible to generate random mazes.
# Coming soon, a blog about mazes
2 changes: 1 addition & 1 deletion src/Mazes.CLI/Canvas/Array2D/Ellipse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Options = {
[<Option(Default = 0, HelpText = "Translation factor on the horizontal axis.")>] rowTranslationFactor : int
[<Option(Default = 0, HelpText = "Translation factor on the vertical axis.")>] columnTranslationFactor : int
[<Option(Default = 0.0, HelpText = "Inside ellipse factor.")>] ellipseFactor : float
[<Option(Default = SideEnum.Inside, HelpText = "Indicate where the ellipse is Inside or Outside." )>] side : SideEnum
[<Option(Default = SideEnum.Inside, HelpText = "Indicate wheter the ellipse is Inside or Outside." )>] side : SideEnum
}

let handleVerb (options : Parsed<Options>) =
Expand Down
2 changes: 1 addition & 1 deletion src/Mazes.CLI/Canvas/ArrayOfA/Disk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let verb = "s-disk"
[<Verb(verb, isDefault = false, HelpText = "Disk shape")>]
type Options = {
[<Option('r', "rings", Required = true, HelpText = "The number of rings.")>] rings : int
[<Option('w', "ratio", Required = true, HelpText = "Width height ratio." )>] ratio : float
[<Option('w', "ratio", Required = true, HelpText = "Width/height ratio." )>] ratio : float
[<Option('c', "center", Required = true, HelpText = "Number of cells for the central ring." )>] center : int
}

Expand Down
1 change: 1 addition & 0 deletions src/Mazes.CLI/Mazes.CLI.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Compile Include="Render\SVG\Brick.fs" />
<Compile Include="Render\Text\Ortho.fs" />
<Compile Include="Output\File.fs" />
<Compile Include="Output\Console.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

Expand Down
17 changes: 17 additions & 0 deletions src/Mazes.CLI/Output/Console.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020-2021 Patrizio Amella. All rights reserved. See License file in the project root for more information.

module Mazes.CLI.Output.Console

open System
open CommandLine

[<Literal>]
let verb = "o-console"

[<Verb(verb, isDefault = false, HelpText = "Output to the console")>]
type Options = {
[<Option()>] noOption : int
}

let handleVerb (data : string) _ =
Console.Write(data)
22 changes: 15 additions & 7 deletions src/Mazes.CLI/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ let mazeToRender argv (maze : MazeChoice) =
| ArrayOfAPolar maze -> handleVerb<SVG.Polar.Options, string> (Some (SVG.Polar.handleVerb maze)) SVG.Polar.verb argv

let renderToOutput argv render =
handleVerb<File.Options, unit> (Some (File.handleVerb render)) File.verb argv
[|
handleVerb<File.Options, unit> (Some (File.handleVerb render)) File.verb argv
handleVerb<Console.Options, unit> (Some (Console.handleVerb render)) Console.verb argv
|] |> pick

let checkAllHandlers argv =
handleVerb<Array2D.Rectangle.Options, Mazes.Core.Canvas.Array2D.Canvas> None Array2D.Rectangle.verb argv |> ignore
Expand Down Expand Up @@ -220,6 +223,7 @@ let checkAllHandlers argv =
handleVerb<Text.Ortho.Options, string> None Text.Ortho.verb argv |> ignore

handleVerb<File.Options, unit> None File.verb argv |> ignore
handleVerb<Console.Options, unit> None Console.verb argv |> ignore

[<EntryPoint>]
let main argv =
Expand All @@ -230,12 +234,16 @@ let main argv =
| 1 ->
checkAllHandlers verbs.[0]
| 5 ->
initCanvas verbs.[0]
|> Option.bind(canvasArray2DToNdStruct verbs.[1])
|> Option.bind(ndStructToMaze verbs.[2])
|> Option.bind(mazeToRender verbs.[3])
|> Option.bind(renderToOutput verbs.[4])
|> ignore
let result =
initCanvas verbs.[0]
|> Option.bind(canvasArray2DToNdStruct verbs.[1])
|> Option.bind(ndStructToMaze verbs.[2])
|> Option.bind(mazeToRender verbs.[3])
|> Option.bind(renderToOutput verbs.[4])

match result with
| Some _ -> printfn "\nMaze generated !"
| None -> printfn "Something went wrong, some chosen actions are not compatible."

| _ -> failwith "Number of verbs not supported"

Expand Down
7 changes: 7 additions & 0 deletions src/Mazes.CLI/Render/SVG/Ortho.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Lines =
| Straight = 0
| Circle = 1
| Curved = 2
| Random = 3

[<Literal>]
let verb = "rs-ortho"
Expand All @@ -21,6 +22,8 @@ type Options = {
[<Option('s', "solution", Required = false, Default = false, HelpText = "Show solution ?")>] solution : bool
[<Option('e', "entranceExit", Required = false, Default = true, HelpText = "Add an entrance and an exit ?")>] entranceExit : bool
[<Option('l', "lines", Required = false, Default = Lines.Straight, HelpText = "Type of lines Straight, Circle or Curved). In circle mode only the Width value is considered; in curved mode you can change the curve option to obtain various effects")>] lines : Lines
[<Option(HelpText = "RNG seed, if none is provided a random one is chosen")>] seed : int option
[<Option(Default = 5.0, HelpText = "Curve multiplication factor")>] curveMultFact : float
[<Option(Default = 30, HelpText = "Width of a single cell")>] width : int
[<Option(Default = 30, HelpText = "Height of a single cell")>] height : int
[<Option(Default = 10.0, HelpText = "Width of the bridge")>] bridgeWidth : float
Expand Down Expand Up @@ -66,6 +69,10 @@ let handleVerb (maze : Maze<_,_>) (options : Parsed<Options>) =
| Lines.Straight -> Straight
| Lines.Circle -> Circle
| Lines.Curved -> (options.Value.curve, options.Value.curve) |> Curve
| Lines.Random ->
match options.Value.seed with
| Some seed -> (System.Random(seed), options.Value.curveMultFact) |> Random
| None -> (System.Random(), options.Value.curveMultFact) |> Random
| _ -> failwith "Unsupported Lines value"
}

Expand Down
27 changes: 19 additions & 8 deletions src/Mazes.Render/SVG/OrthoGrid.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Line =
| Straight
| Circle
| Curve of (int * int)
| Random of (System.Random * float)

type Parameters =
{
Expand All @@ -27,13 +28,23 @@ type Parameters =
MarginHeight : int
Line : Line
}
member this.Radius =

member this.PerfectRadius =
let perfectRadius = (pythagorasHypotenuse ((float)this.Width) ((float)this.Height) / 2.0)
(perfectRadius, perfectRadius)

member this.Radius() =
match this.Line with
| Straight -> (0.0, 0.0)
| Circle ->
let perfectRadius = (pythagorasHypotenuse ((float)this.Width) ((float)this.Height) / 2.0)
(perfectRadius, perfectRadius)
| Circle -> this.PerfectRadius
| Curve (rx, ry) -> ((float)rx, (float)ry)
| Random (rng, mult) ->
let min = fst this.PerfectRadius
let max = min * mult
let nextFloat =
rng.NextDouble() * (max - min) + min

(nextFloat, nextFloat)

static member CreateDefaultSquare =
{
Expand Down Expand Up @@ -79,7 +90,7 @@ let private appendWallsType (parameters : Parameters) calculatePoints getLine (g

let orientation = if (coordinate2D.RIndex + coordinate2D.CIndex) % 2 = 0 then "0" else "1"

let (rx, ry) = parameters.Radius
let (rx, ry) = parameters.Radius()

// let (rx, ry) =
// let (rx, ry) = parameters.Radius
Expand All @@ -101,7 +112,7 @@ let private appendWallsType (parameters : Parameters) calculatePoints getLine (g
| Top -> getLine straightLine (leftTopX, leftTopY) (rightTopX, rightTopY)
| Right -> getLine straightLine (rightBottomX, rightBottomY) (rightTopX, rightTopY)
| Bottom -> getLine straightLine (leftBottomX, leftBottomY) (rightBottomX, rightBottomY)
| Circle | Curve _ ->
| Circle | Curve _ | Random _ ->
let arcLine = arcLine orientation (rx, ry)
match position with
| Left -> getLine arcLine (leftTopX, leftTopY) (leftBottomX, leftBottomY)
Expand All @@ -120,15 +131,15 @@ let private wholeCellLines (parameters : Parameters) calculatePoints (coordinate

let coordinate2D = coordinate.ToCoordinate2D
let orientation = if (coordinate2D.RIndex + coordinate2D.CIndex) % 2 = 0 then "0" else "1"
let (rx, ry) = parameters.Radius
let (rx, ry) = parameters.Radius()

match parameters.Line with
| Straight ->
$"M {round leftBottomX} {round leftBottomY} " +
$"L {round rightBottomX} {round rightBottomY} " +
$"L {round rightTopX} {round rightTopY} " +
$"L {round leftTopX} {round leftTopY} "
| Circle | Curve _ ->
| Circle | Curve _ | Random _ ->
$"M {round leftTopX} {round leftTopY} A {round rx} {round ry}, 0, 0, {orientation}, {round leftBottomX} {round leftBottomY} " +
$"A {round rx} {round ry}, 0, 0, {orientation}, {round rightBottomX} {round rightBottomY} " +
$"A {round rx} {round ry}, 0, 0, {orientation}, {round rightTopX} {round rightTopY} " +
Expand Down

0 comments on commit 0d35f29

Please sign in to comment.