ca-patterns-0.2.0.0: Manipulate patterns in cellular automata, create and parse RLE files
Safe HaskellNone
LanguageHaskell2010

Data.CA.Pattern

Description

The functions in this module allow you to create, transform, and combine CA patterns.

Synopsis

Cells

type Cell = Bool Source #

The state of a cell. True represents a live cell and False represents a dead cell.

Patterns

data Pattern Source #

A pattern in a 2-dimensional 2-state cellular automaton.

Instances

Instances details
Eq Pattern Source # 
Instance details

Defined in Data.CA.Pattern

Methods

(==) :: Pattern -> Pattern -> Bool #

(/=) :: Pattern -> Pattern -> Bool #

Show Pattern Source # 
Instance details

Defined in Data.CA.Pattern

lookup Source #

Arguments

:: Int

row

-> Int

column

-> Pattern 
-> Cell 

Get the state of one of the cells in a pattern. lookup 0 0 returns the cell in the upper-left corner. If the row or column number is out of range, this function will return False.

generate Source #

Arguments

:: Int

height

-> Int

width

-> (Int -> Int -> Cell)

function taking row and column

-> Pattern 

Generate a pattern from a function.

dimensions :: Pattern -> (Int, Int) Source #

Get the height and width of a pattern.

valid :: Pattern -> Bool Source #

Test if a pattern is valid, i.e. rectangular. Some of the functions in this module only behave properly on rectangular patterns.

Vector conversions

fromRectVector :: Vector (Vector Cell) -> Pattern Source #

Convert a vector of rows into a pattern, assuming the rows are all the same length.

fromVector :: Vector (Vector Cell) -> Pattern Source #

Convert a vector of rows into a pattern. If the rows are not all the same length, they will padded with dead cells until the pattern is rectangular.

toVector :: Pattern -> Vector (Vector Cell) Source #

Convert a pattern into a vector of rows.

List conversions

fromRectList :: [[Cell]] -> Pattern Source #

Convert a list of rows into a pattern, assuming the rows are all the same length.

fromList :: [[Cell]] -> Pattern Source #

Convert a list of rows into a pattern. If the rows are not all the same length, they will padded with dead cells until the pattern is rectangular.

toList :: Pattern -> [[Cell]] Source #

Convert a pattern into a list of rows.

Text and string conversions

toText Source #

Arguments

:: Char

dead cell

-> Char

live cell

-> Pattern 
-> Text 

Convert a pattern into text. For example, toText '.' 'Z' will replace each dead cell with a . and each live cell with a Z.

toString Source #

Arguments

:: Char

dead cell

-> Char

live cell

-> Pattern 
-> String 

Convert a pattern into a string.

Trimming

trimTop :: Pattern -> Pattern Source #

Remove rows of dead cells from the top of a pattern.

trimBottom :: Pattern -> Pattern Source #

Remove rows of dead cells from the bottom of a pattern.

trimLeft :: Pattern -> Pattern Source #

Remove columns of dead cells from the left side of a pattern.

trimRight :: Pattern -> Pattern Source #

Remove columns of dead cells from the right side of a pattern.

trim :: Pattern -> Pattern Source #

A composition of trimTop, trimBottom, trimLeft, and trimRight. Removes as many dead cells from the pattern as possible while keeping it rectangular.

Cropping and padding

setHeight :: Int -> Pattern -> Pattern Source #

Force a pattern to have the given height by removing rows from the bottom or by adding rows of dead cells.

setWidth :: Int -> Pattern -> Pattern Source #

Force a pattern to have the given width by removing columns from the right or by adding columns of dead cells.

setDimensions :: Int -> Int -> Pattern -> Pattern Source #

Set the height and width of a pattern.

Transformations

reflectX :: Pattern -> Pattern Source #

Reflect horizontally, switching the left and the right.

reflectY :: Pattern -> Pattern Source #

Reflect vertically, switching the top and the bottom.

rotateL :: Pattern -> Pattern Source #

Rotate counterclockwise by a quarter turn.

rotateR :: Pattern -> Pattern Source #

Rotate clockwise by a quarter turn.

Combining

combine Source #

Arguments

:: Int

vertical offset

-> Int

horizontal offset

-> Pattern 
-> Pattern 
-> Pattern 

Combine two patterns given a vertical and horizontal offset, which describe the displacement of the second pattern relative to the first one.