-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Flexible generation of identicons -- -- Flexible generation of identicons. @package identicon @version 0.2.2 -- | Core types and definitions for flexible generation of identicons. -- Please see the Graphics.Identicon.Primitive module for a -- collection of building blocks to code layers of your identicon. -- -- A basic complete example looks like this: -- --
-- import Codec.Picture -- import Data.ByteString (ByteString) -- import Data.Proxy -- import Data.Word (Word8) -- import Graphics.Identicon -- import Graphics.Identicon.Primitive -- -- myImageType :: Proxy (Identicon 4 :+ Consumer 4) -- myImageType = Proxy -- -- myImpl = Identicon :+ a -- where -- a :: Word8 -> Word8 -> Word8 -> Word8 -> Layer -- a r g b n = rsym $ onGrid 6 6 n $ -- circle $ gradientLR (edge . mid) black (PixelRGB8 r g b) -- -- myGenerator :: Int -> Int -> ByteString -> Maybe (Image PixelRGB8) -- myGenerator = renderIdenticon myImageType myImpl ---- -- myGenerator takes desired width, height, and hash that should -- have at least 4 bytes in it and returns an identicon corresponding to -- that hash or Nothing if the hash has less than 4 bytes in it or -- width/height don't make sense. The identicon has randomly placed -- circle with gradient filling changing (horizontally) from black to -- some color and back to black. The circle is mirrored 4 times, and -- every repetition is rotated by 90°. This identicon consumes 4 bytes -- and has one layer. module Graphics.Identicon -- | Identicon is a type that represents an identicon consisting of -- zero layers. The type is parametrized over a phantom type n -- which is a natural number on the type level that represents the number -- of bytes that should be provided to generate this type of identicon. -- Bytes typically come from some sort of hash that has a fixed size. data Identicon (n :: Nat) Identicon :: Identicon -- | Consumer is a type that represents an entity that consumes -- bytes that are available for identicon generation. It's parametrized -- over a phantom type n which is a natural number on the type -- level that represents the number of bytes that this entity consumes. -- At this moment, a Consumer always adds one Layer to -- identicon when attached to it. The number of bytes, specified as type -- parameter of Identicon type must be completely consumed by a -- collection of consumers attached to it. To attach a consumer to -- Identicon, you use the (:+) type operator, see -- below. data Consumer (n :: Nat) -- | The (:+) type operator is used to attach -- Consumers to Identicon, thus adding layers to it and -- exhausting bytes that are available for identicon generation. An -- example of identicon that can be generated from 16 byte hash is shown -- below: -- --
-- type Icon = Identicon 16 :+ Consumer 5 :+ Consumer 5 :+ Consumer 6 ---- -- The identicon above has three layers. data (:+) a b (:+) :: a -> b -> (:+) a b -- | Layer is the basic building block of an identicon. It's a -- function that takes the following arguments (in order): -- --
-- 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. module Graphics.Identicon.Primitive -- | 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. black :: PixelRGB8 -- | Layer filled with a given color. color :: PixelRGB8 -> Layer -- | Gradient changing from left to right. gradientLR :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer -- | Gradient changing from top to bottom. gradientTB :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer -- | Gradient changing from top left corner to bottom right corner. gradientTLBR :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer -- | Gradient changing from top right corner to bottom left corner. gradientTRBL :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer -- | Gradient with one color everywhere and another in the center. gradientXY :: (Float -> Float) -> PixelRGB8 -> PixelRGB8 -> Layer -- | 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. mid :: Float -> Float -- | This sharpens gradient transitions. edge :: Float -> Float -- | 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. onGrid :: Integral a => Int -> Int -> a -> Layer -> Layer -- | Limit given layer so it forms a circle. circle :: Layer -> Layer -- | Add horizontal symmetry to a layer. hsym :: Layer -> Layer -- | Add vertical symmetry to a layer. vsym :: Layer -> Layer -- | Add horizontal and vertical symmetry to layer. Result is a layer with -- four mirrored repetitions of the same figure. hvsym :: Layer -> Layer -- | Just like hvsym, but every repetition is rotated by 90°. Only -- works with square layers because for speed it just swaps coordinates. rsym :: Layer -> Layer -- | Select one of provided alternatives given a number. oneof :: Integral n => [a] -> n -> a