`celtic-knot`

Celtic Knot Cartesian Grid Matrix Pattern Generator for Scaleable Vector Graphics

** celtic-knot** is a Ruby programme that creates simple rectangular celtic knot drawings based upon a given set of parameters.

## Synopsis

The drawing is in SVG (Scaleable Vector Graphics) format, which is sent to standard output.

## Usage

```
Usage: ./knot [options]
-h, --help Prints this help
-V, --vertical=VERTICAL Number of cells vertically.
-H, --horizontal=HORIZONTAL Number of cells horizontally.
-G, --cell-size=CELL_SIZE Dimensions of each cell in the grid.
-b, --background-color=BG_COLOR Background colour.
-k, --knot-color=KNOT_COLOR Knot colour.
-K, --knot-width=KNOT_WIDTH Knot width.
-s, --stroke-color=STROKE_COLOR Stroke colour.
-S, --stroke-width=STROKE_WIDTH Stroke width.
```

### Examples

#### Basic

```
$ ./knot \
--vertical=2 \
--horizontal=2 \
--cell-size=96 \
--knot-color='white' \
--knot-width=24 \
--stroke-color=black \
--stroke-width=8 \
> examples/basic.svg
```

#### Ingƿine

```
$ ./knot \
--vertical=3 \
--horizontal=4 \
--cell-size=96 \
--background-color='#012169' \
--knot-color='#C8102E' \
--knot-width=32 \
--stroke-color=white \
--stroke-width=16 \
> examples/ingwine.svg
```

#### Bratach (Banner)

```
$ ./knot \
--vertical=5 \
--horizontal=6 \
--cell-size=64 \
--background-color='#169B62' \
--knot-color='#FF883E' \
--knot-width=32 \
--stroke-color=white \
--stroke-width=4 \
> examples/bratach.svg
```

### Converting SVG to Other Formats

The SVG file can be viewed locally in your Web browser or converted into other formats such as PNG using utilities such as ImageMagick's `convert`

. For example:

```
convert -background none examples/basic.svg examples/basic.png
```

## Internals

TODO: Move to API reference docs.

The programme generates SVG output using the Nokogiri library for XML.

The knot is modelled as a two dimensional matrix (`Knot::Grid`

), which itself contains cells (`Knot::Cell`

), which then contains absolutely positioned precalculated points (`Knot::Point`

) that are used for pathing by the drawing engine (`Knot`

.)

### Modules

`Knot`

The drawing engine.

### Classes

`Knot::Grid`

The grid is a `Matrix`

of cells (arranged as rows and columns.) The grid can be nagivated with absolute coordinates using the `position(i, j)`

method and nearby cells accessed relatively using the `rel(i, j)`

method.

`Knot::Cell`

Each cell within the grid contains several cartesian points stored in hashes. These points are precaclulated so that minimal calculations are required when pathing.

`Knot::Point`

Each point is modelled in the cartesian plane as a `Vector[x, y]`

.

`Knot::Path`

Models an SVG path.

### Class Methods

`Knot::Point.midpoint(a, b)`

Calculates the midpoint between two points. Used where a desired point has not been precalculated but can instead be derived from another pair of points that *are* precalculated.

`Knot::Point.distance(a, b)`

Calculates the distance between two points. Used for calculating radii for arc curves.

## Author

2023 Damien Bezborodov