Copyright | © 2016–2017 Mark Karpov |
---|---|

License | BSD 3 clause |

Maintainer | Mark Karpov <markkarpov92@gmail.com> |

Stability | experimental |

Portability | portable |

Safe Haskell | None |

Language | Haskell2010 |

Various primitives and combinators that help you write code for your
identicon. Filling functions is where you start. They create color layers
that occupy all available space. If you want to limit a layer in size,
specify where this smaller part should be, take a look at the “Position,
size, and shape” section. It also contains the `circle`

combinator that
limits a given filling is such a way that it forms a circle. Finally, we
have combinators that add symmetry to layers and other auxiliary
functions.

As a starting point, here is the function that generates a circle with gradient filling changing from black (on the left hand side) to some color (on the right hand side):

f :: Word8 -> Word8 -> Word8 -> Layer f r g b = circle $ gradientLR id black (PixelRGB8 r g b)

The function consumes 3 bytes from a hash when it's used in identicon.

- black :: PixelRGB8
- color :: PixelRGB8 -> Layer
- gradientLR :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer
- gradientTB :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer
- gradientTLBR :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer
- gradientTRBL :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer
- gradientXY :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer
- mid :: Float -> Float
- edge :: Float -> Float
- onGrid :: Integral a => Int -> Int -> a -> Layer -> Layer
- circle :: Layer -> Layer
- hsym :: Layer -> Layer
- vsym :: Layer -> Layer
- hvsym :: Layer -> Layer
- rsym :: Layer -> Layer
- oneof :: Integral n => [a] -> n -> a

# Filling

Black is a special color, it means absence of light. We give this pixel a name because it's used very frequently in layer coding.

:: (Float -> Float) | Gradient transforming function |

-> PixelRGB8 | Left color |

-> PixelRGB8 | Right color |

-> Layer |

Gradient changing from left to right.

:: (Float -> Float) | Gradient transforming function |

-> PixelRGB8 | Top color |

-> PixelRGB8 | Bottom color |

-> Layer |

Gradient changing from top to bottom.

:: (Float -> Float) | Gradient transforming function |

-> PixelRGB8 | Top left color |

-> PixelRGB8 | Bottom right color |

-> Layer |

Gradient changing from top left corner to bottom right corner.

:: (Float -> Float) | Gradient transforming function |

-> PixelRGB8 | Top right color |

-> PixelRGB8 | Bottom left color |

-> Layer |

Gradient changing from top right corner to bottom left corner.

:: (Float -> Float) | Gradient transforming function |

-> PixelRGB8 | “Edge” color |

-> PixelRGB8 | Color in the center |

-> Layer |

Gradient with one color everywhere and another in the center.

## Gradient transforming functions

A note about “gradient transforming functions”: these normally map value changing from 0 to 1 somehow, but they should not produce values outside of that range. With help of such functions you can change character of gradient transitions considerably.

mid :: Float -> Float Source #

A built-in gradient transforming function. It maps continuous floating value changing from 0 to 1 to value changing from 0 to 1 (in the middle) and back to 0.

# Position, size, and shape

:: Integral a | |

=> Int | Number of horizontal positions |

-> Int | Number of vertical positions |

-> a | Index of this cell |

-> Layer | Layer to insert |

-> Layer | Resulting layer |

`onGrid w h n l`

, given grid that has `w`

horizontal discrete positions
(of equal length) and `h`

vertical positions, it makes given layer `l`

occupy cell at index `n`

. This approach allows you control position and
size at the same time.

The index `n`

can be greater than maximal index, in this case reminder of
division of `n`

by `w * h`

is used.

# Symmetry

hvsym :: Layer -> Layer Source #

Add horizontal and vertical symmetry to layer. Result is a layer with four mirrored repetitions of the same figure.

rsym :: Layer -> Layer Source #

Just like `hvsym`

, but every repetition is rotated by 90°. Only works
with square layers because for speed it just swaps coordinates.