Module Kwpicture

module Kwpicture: sig .. end

Two-dimensional "ASCII" pictures.

Implemented as list of columns.
Author(s): Keith Waclena


type t 
The type of pictues.
val nil : t
The empty picture (identity element for most of the following functions).
val pic : ?c:char -> int * int -> t
pic ?c (h,w): create a picture of height h and witdh w consisting of c characters.

The null picture (0,0) is valid, but (0,w) and (h,0) are impossible.

Example: pic ~c:'.' (3,3) yields:

...
...
...

c : the character the picture will consist of (default: ' ' (space))
val height : t -> int
height pic: return height of picture.
val width : t -> int
width pic: return width of picture.
val copy : int -> t -> t list
copy n pic: return a list consisting of n copies of picture p.
val row : string -> t
row str: convert a string of length n to a 1xn picture representing that string as a single row.
val col : string -> t
col str: convert string str to a (String.length str)x1 picture representing that string as a single column.
val above : t -> t -> t
above a b: return a picture consisting of pictures a and b on top of each other (a above b).

Example: above (row "--+") (row "*==") yields:

--+
*==

val beside : t -> t -> t
beside a b: return a picture consisting of pictures a and b beside each other (a on the left).

Example: let x = above (row "--+") (row "*==") in beside x x yields:

--+--+
*==*==

val stack : t list -> t
stack pics: return a picture consisting of all the pictures in the list, set each above the other (first picture on top).

Example: stack (copy 4 (row "--+")) yields:

--+
--+
--+
--+

val spread : t list -> t
spread pics: return a picture consisting of all the pictures in the list, set each beside the other (first picture on the left).

Example: spread (copy 3 (stack (copy 4 (row "--+")))) yields:

--+--+--+
--+--+--+
--+--+--+
--+--+--+

val flipH : t -> t
flipH pic: flip the picture horizontally (i.e. left becomes right).

Example: beside (above (row "---") (row "---")) (above (row "+++") (row "+++")) yields:

---+++
---+++
and flipH (beside (above (row "---") (row "---")) (above (row "+++") (row "+++"))) yields:
+++---
+++---

val flipV : t -> t
flipV pic: flip the picture vertically (i.e. make it upside-down).

Example: above (row "---") (row "+++") yields:

---
+++
and flipV (above (row "---") (row "+++")) yields:
+++
---

val block : int -> t list -> t
block n pics: return the picture consisting of the pictures in pics taken n at a time.

Example: block 3 (copy 12 (row "--+")) yields:

--+--+--+
--+--+--+
--+--+--+
--+--+--+

val blockT : int -> t list -> t
blockT n pics: the transpose of block n pics.

Example: blockT 3 (copy 12 (row "--+")) yields:

--+--+--+--+
--+--+--+--+
--+--+--+--+

type position = 
| NW
| N
| NE
| W
| C
| E
| SW
| S
| SE
The type of frame positions.
val frame : ?c:char -> position -> int * int -> t -> t
frame ?c pos (h,w) p: return the picture consisting of p set in the an h x w picture (i.e. a background of c's). The position pos determines where p is positioned:

------------
-NW--N---NE-
------------
------------
-W---C---E--
------------
------------
-SW--S---SE-
------------

Example: frame ~c:'.' NW (4,5) (pic ~c:'+' (2,3)) yields:

+++..
+++..
.....
.....

c : the character the background will consist of (default: ' ' (space))
val to_string : t -> string
to_string pic: convert picture p to a string.
val display : ?h:char -> ?v:char -> t -> t
display p: put a border around picture p to make it easy to see the extent of the picture.
h : horizontal frame character (default: '-')
v : vertical frame character (default: '|')
val print : t -> unit
print pic: convenience function to print a picture to stdout.