pixelated-avatar-generator-0.1.0: A library and application for generating pixelated avatars.

Copyright(c) Christopher Wells, 2016
LicenseMIT
Maintainercwellsny@nycap.rr.com
Safe HaskellNone
LanguageHaskell2010

Graphics.Avatars.Pixelated

Contents

Description

This module provides types and functions for creating and working with pixelated avatars.

Avatars can be generated by providing a Seed. Seeds can be created by passing a random String into createSeed. The given String is then turned into an MD5 checksum, which is used as the seed value.

Once a Seed has been created, an Avatar can be generated from it by passing it into generateAvatar. By default, Avatars start at a size of 8x8px. The size of an Avatar can be increased by passing it into scaleAvatar. Once you have scaled the Avatar to the size you want it to be it can then be saved to a file by passing it into saveAvatar.

Example

The following is an example showing how to construct a function which will generate a 256x256px avatar from a given seed string, and save it at the given location.

import Graphics.Avatars.Pixelated

createAndSaveAvatar :: String -> FilePath -> IO ()
createAndSaveAvatar s path = saveAvatar avatar path
  where avatar = scaleAvatar 32 $ generateAvatar seed
        seed   = createSeed s

Synopsis

Types

Seed

newtype Seed Source #

A seed to use in generating an avatar. Can be created from a String by using the createSeed function.

Seeds are expected to be 32 character hexidecimal MD5 checksums.

Constructors

Seed 

Fields

Instances

Eq Seed Source # 

Methods

(==) :: Seed -> Seed -> Bool #

(/=) :: Seed -> Seed -> Bool #

Show Seed Source # 

Methods

showsPrec :: Int -> Seed -> ShowS #

show :: Seed -> String #

showList :: [Seed] -> ShowS #

createSeed :: String -> Seed Source #

Creates a seed from a given String.

>>> createSeed "Hello"
Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"}

Avatar

data Avatar Source #

A generated avatar.

Constructors

Avatar 

Fields

Instances

generateAvatar :: Seed -> Avatar Source #

Generates an avatar from the given seed.

scaleAvatar :: Int -> Avatar -> Avatar Source #

Scales the given Avatar by the given scaling factor.

saveAvatar :: Avatar -> FilePath -> IO () Source #

Saves the given avatar to the given file path.

makeAvatar :: Seed -> FilePath -> IO ()
makeAvatar seed path = do
  let avatar = generateAvatar seed path
  saveAvatar avatar path

convertAvatarToImage :: Avatar -> Image PixelRGB8 Source #

Converts the given Avatar into an Image.

Color

data Color Source #

A color for an avatar.

Constructors

Black 
Blue 
Green 
Grey 
Orange 
Purple 
Red 
Yellow 

Instances

Eq Color Source # 

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

Show Color Source # 

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

getColorValue :: Color -> PixelRGB8 Source #

Converts the given color into a RGB pixel representation.

colorFromSeed :: Seed -> Color Source #

Picks an avatar color using the given seed.

>>> colorFromSeed $ Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"}
Orange

Avatar Grid

newtype AvatarGrid Source #

A grid of boolean values representing an Avatar. True values indicate colored pixels, and False values indicate blank pixels.

Constructors

AvatarGrid 

Fields

Instances

Eq AvatarGrid Source # 
Show AvatarGrid Source #

Converts the grid into a String representation.

showGrid :: [[Bool]] -> String Source #

Converts a grid of boolean values into a String representation.

>>> putStrLn $ showGrid [[True, False], [False, True]]
█ 
 █

generateAvatarGrid :: Seed -> AvatarGrid Source #

Generates an AvatarGrid using the given Seed.

It works by generating the left half of the grid using the contents of the Seed, and then mirroring the left half to create the full grid.

>>> generateAvatarGrid Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"}
██ ██ ██
██    ██
█      █
  █  █  
██    ██
████████
█  ██  █
  █  █  

Utility

scaleList :: Int -> [a] -> [a] Source #

Scales the given list by the given scaling factor.

>>> scaleList 2 [1, 2]
[1,1,2,2]
>>> scaleList 3 [0, 1]
[0,0,0,1,1,1]