identicon-0.2.2: Flexible generation of identicons

Copyright© 2016–2017 Mark Karpov
LicenseBSD 3 clause
MaintainerMark Karpov <markkarpov92@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Graphics.Identicon.Primitive

Contents

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

Synopsis

Filling

black :: PixelRGB8 Source #

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.

color :: PixelRGB8 -> Layer Source #

Layer filled with a given color.

gradientLR Source #

Arguments

:: (Float -> Float)

Gradient transforming function

-> PixelRGB8

Left color

-> PixelRGB8

Right color

-> Layer 

Gradient changing from left to right.

gradientTB Source #

Arguments

:: (Float -> Float)

Gradient transforming function

-> PixelRGB8

Top color

-> PixelRGB8

Bottom color

-> Layer 

Gradient changing from top to bottom.

gradientTLBR Source #

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.

gradientTRBL Source #

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.

gradientXY Source #

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.

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.

edge :: Float -> Float Source #

This sharpens gradient transitions.

Position, size, and shape

onGrid Source #

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.

circle :: Layer -> Layer Source #

Limit given layer so it forms a circle.

Symmetry

hsym :: Layer -> Layer Source #

Add horizontal symmetry to a layer.

vsym :: Layer -> Layer Source #

Add vertical symmetry to a layer.

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.

Other

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

Select one of provided alternatives given a number.