identicon-0.2.1: Flexible generation of identicons

Graphics.Identicon.Primitive

Description

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 a circle combinator that limits 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 hash when it's used in identicon.

Synopsis

# 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.

Layer filled with a given color.

Arguments

 :: (Float -> Float) Gradient transforming function -> PixelRGB8 Left color -> PixelRGB8 Right color -> Layer

Gradient changing from left to right.

Arguments

 :: (Float -> Float) Gradient transforming function -> PixelRGB8 Top color -> PixelRGB8 Bottom color -> Layer

Gradient changing from top to bottom.

Arguments

 :: (Float -> Float) Gradient transforming function -> PixelRGB8 Top left color -> PixelRGB8 Bottom right color -> Layer

Gradient changing from top left corner to bottom right corner.

Arguments

 :: (Float -> Float) Gradient transforming function -> PixelRGB8 Top right color -> PixelRGB8 Bottom left color -> Layer

Gradient changing from top right corner to bottom left corner.

Arguments

 :: (Float -> Float) Gradient transforming function -> PixelRGB8 “Edge” color -> PixelRGB8 Color in the center -> Layer

Gradient with one color everywhere and another in the center.

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.

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

Arguments

 :: 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.

Limit given layer so it forms a circle.

# Symmetry

Add horizontal symmetry to a layer.

Add vertical symmetry to a layer.

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

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

# Other

oneof :: Integral n => [a] -> n -> a Source #

Select one of provided alternatives given a number.