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

Graphics.Avatars.Pixelated

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.

By default, the saveAvatar function saves the avatar as a png image file, however you can also save avatars in other image formats by using saveAvatarWith. It allows you to specify the function to use to convert the avatar image into an image ByteString.

# 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 FieldsunSeed :: String Instances  Source # Methods(==) :: Seed -> Seed -> Bool #(/=) :: Seed -> Seed -> Bool # Source # MethodsshowsPrec :: Int -> Seed -> ShowS #show :: Seed -> String #showList :: [Seed] -> ShowS # Creates a seed from a given String. >>> createSeed "Hello" Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"}  ## Avatar data Avatar Source # A generated avatar, comprised of a color and a grid representing the visual pattern of the avatar image. Can be created from a seed using generateAvatar. Avatars are generated at a size of 8x8px, and can be scaled up to larger image sizes by using the scaleAvatar function. Constructors  Avatar Fieldscolor :: Color grid :: AvatarGrid Instances  Source # Methods(==) :: Avatar -> Avatar -> Bool #(/=) :: Avatar -> Avatar -> Bool # Source # Generates a String containing the color and pattern of the avatar. MethodsshowsPrec :: Int -> Avatar -> ShowS #showList :: [Avatar] -> ShowS # Generates an avatar from the given seed. >>> generateAvatar Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"} Grey ██ ██ ██ ██ ██ █ █ █ █ ██ ██ ████████ █ ██ █ █ █  Scales the given Avatar by the given scaling factor. For example, scaling an 8x8px avatar by a factor of 4 would transform it into a 32x32px avatar. Saves the given avatar as a png image file to the given file path. The filepath should be the path and name of the image file to be created, including the file extension. For saving an avatar in a non-png format, use saveAvatarWith. makeAvatar :: Seed -> FilePath -> IO () makeAvatar seed path = do let avatar = generateAvatar seed path saveAvatar avatar path  Saves the given avatar to the given file location, using the given function to encode it into a specific image format. Some examples of encoding functions are encodeToGif and encodeToTiff. saveTiffAvatar :: Seed -> FilePath -> IO () saveTiffAvatar seed path = do let avatar = generateAvatar seed path saveAvatarWith encodeTiff avatar path  Converts the given Avatar into an Image. ### Image Conversion A function which converts an image into a lazy ByteString. Converts an image into a Png image ByteString. Converts an image into a Gif image ByteString. Converts an image into a Tiff image ByteString. ## Color data Color Source # A color of an avatar. The color of an avatar is the color that is applied to the pattern of the avatar when it is converted into an image. Constructors  Black Blue Green Grey Orange Purple Red Yellow Instances  Source # Methodssucc :: Color -> Color #pred :: Color -> Color #toEnum :: Int -> Color #enumFrom :: Color -> [Color] #enumFromThen :: Color -> Color -> [Color] #enumFromTo :: Color -> Color -> [Color] #enumFromThenTo :: Color -> Color -> Color -> [Color] # Source # Methods(==) :: Color -> Color -> Bool #(/=) :: Color -> Color -> Bool # Source # MethodsshowsPrec :: Int -> Color -> ShowS #show :: Color -> String #showList :: [Color] -> ShowS # Converts the given color into a RGB pixel representation. >>> getColorValue Orange PixelRGB8 255 140 65  Picks an avatar color using the given seed. Each of the eight possible colors has roughly an equal chance of being chosen with a random seed. >>> colorFromSeed$ Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"}
Grey


## 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 FieldsunAvatarGrid :: [[Bool]]

Instances

 Source # Methods Source # Converts the grid into a String representation. MethodsshowList :: [AvatarGrid] -> ShowS #

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

Converts a grid of boolean values into a String representation.

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


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]