Skip to content

Commit

Permalink
Improve the documentation
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
mrkkrp committed May 22, 2017
1 parent 8cf721c commit 309b4a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
17 changes: 8 additions & 9 deletions Graphics/Identicon.hs
Expand Up @@ -135,30 +135,30 @@ instance Monoid Layer where
mempty = Layer $ \_ _ _ _ -> PixelRGB8 0 0 0
mappend = (S.<>)

-- | The 'BytesAvailable' type function calculates how many bytes available
-- for consumption in a given identicon.
-- | The 'BytesAvailable' type function calculates how many bytes are
-- available for consumption in a given identicon.

type family BytesAvailable a :: Nat where
BytesAvailable (Identicon n) = n
BytesAvailable (x :+ y) = BytesAvailable x

-- | The 'BytesConsumed' type function calculates how many bytes is consumed
-- in a given identicon.
-- | The 'BytesConsumed' type function calculates how many bytes are
-- consumed in a given identicon.

type family BytesConsumed a :: Nat where
BytesConsumed (Identicon n) = 0
BytesConsumed (Consumer n) = n
BytesConsumed (x :+ y) = BytesConsumed x + BytesConsumed y

-- | The 'Implementation' type function returns type of the code which can
-- implement the given identicon.
-- | The 'Implementation' type function returns the type of the code which
-- can implement the given identicon.

type family Implementation a where
Implementation (Identicon n) = Identicon n
Implementation (a :+ Consumer n) = Implementation a :+ ToLayer n

-- | The 'ToLayer' type function calculates type that a layer-producing
-- function should have to consume given number of bytes @n@.
-- function should have to consume the given number of bytes @n@.

type family ToLayer (n :: Nat) :: k where
ToLayer 0 = Layer
Expand Down Expand Up @@ -198,8 +198,7 @@ mixPixels
mixPixels a b x y = mixWith (const saturatedAddition) (a x y) (b x y)
{-# INLINE mixPixels #-}

-- | An implementation of saturated addition for bytes. This is a reasonably
-- efficient thing.
-- | An implementation of saturated addition for bytes.

saturatedAddition :: Word8 -> Word8 -> Word8
saturatedAddition x y = let z = x + y in
Expand Down
2 changes: 1 addition & 1 deletion Graphics/Identicon/Primitive.hs
Expand Up @@ -23,7 +23,7 @@
-- > 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.
-- The function consumes 3 bytes from a hash when it's used in identicon.

module Graphics.Identicon.Primitive
( -- * Filling
Expand Down
17 changes: 8 additions & 9 deletions README.md
Expand Up @@ -7,16 +7,14 @@
[![Build Status](https://travis-ci.org/mrkkrp/identicon.svg?branch=master)](https://travis-ci.org/mrkkrp/identicon)
[![Coverage Status](https://coveralls.io/repos/mrkkrp/identicon/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrkkrp/identicon?branch=master)

The package implements flexible generation of identicons using the
[Juicy Pixels](https://hackage.haskell.org/package/JuicyPixels) package.
It's reasonably fast for my taste, and since identicons are usually not
bigger than 420 × 420 pixels, I think that sequential generation that
JuicyPixels supports fits the task very well.
The package implements a flexible framework for identicons generation on top
of the [Juicy Pixels](https://hackage.haskell.org/package/JuicyPixels)
package.

## Quick start

To use the package you usually need the following set of imports (and a
couple of language extensions for type level magic):
couple of language extensions for the type level magic):

```haskell
{-# LANGUAGE DataKinds #-}
Expand Down Expand Up @@ -67,8 +65,8 @@ Every byte is available to the layer-generating function as a distinct

* you have as many layers as you described in type of your identicon;

* every function in your implementation has correct signature (i.e. it grabs
as many `Word8`s as promised and produces a `Layer` in the end).
* every function in your implementation has a correct signature (i.e. it
grabs as many `Word8`s as promised and produces a `Layer` in the end).

Mixing of layers and generation is handled by the library like this:

Expand All @@ -86,7 +84,8 @@ genMyIdenticon
genMyIdenticon = renderIdenticon (Proxy :: Proxy MyIcon) myImpl
```

For more information head straight to Haddocks. BTW, I have written
For more information head straight to the Haddocks. BTW, I have
written
[a blog post](https://mrkkrp.github.io/posts/the-identicon-package.html)
about the package where I demonstrate some pictures generated with it.

Expand Down

0 comments on commit 309b4a8

Please sign in to comment.