Safe Haskell | None |
---|---|
Language | Haskell2010 |
The functions in this module allow you to create, transform, and combine CA patterns.
Synopsis
- type Cell = Bool
- data Pattern
- lookup :: Int -> Int -> Pattern -> Cell
- generate :: Int -> Int -> (Int -> Int -> Cell) -> Pattern
- height :: Pattern -> Int
- width :: Pattern -> Int
- dimensions :: Pattern -> (Int, Int)
- valid :: Pattern -> Bool
- fromRectVector :: Vector (Vector Cell) -> Pattern
- fromVector :: Vector (Vector Cell) -> Pattern
- toVector :: Pattern -> Vector (Vector Cell)
- fromRectList :: [[Cell]] -> Pattern
- fromList :: [[Cell]] -> Pattern
- toList :: Pattern -> [[Cell]]
- toText :: Char -> Char -> Pattern -> Text
- toString :: Char -> Char -> Pattern -> String
- trimTop :: Pattern -> Pattern
- trimBottom :: Pattern -> Pattern
- trimLeft :: Pattern -> Pattern
- trimRight :: Pattern -> Pattern
- trim :: Pattern -> Pattern
- setHeight :: Int -> Pattern -> Pattern
- setWidth :: Int -> Pattern -> Pattern
- setDimensions :: Int -> Int -> Pattern -> Pattern
- reflectX :: Pattern -> Pattern
- reflectY :: Pattern -> Pattern
- rotateL :: Pattern -> Pattern
- rotateR :: Pattern -> Pattern
- combine :: Int -> Int -> Pattern -> Pattern -> Pattern
Cells
Patterns
A pattern in a 2-dimensional 2-state cellular automaton.
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 a pattern from a function.
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.
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.
Text and string conversions
Convert a pattern into text. For example, toText '.' 'Z'
will replace each dead cell with a .
and each live cell
with a Z
.
Convert a pattern into a string.
Trimming
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.