Copyright | (c) Christopher Wells, 2016 |
---|---|
License | MIT |
Maintainer | cwellsny@nycap.rr.com |
Safe Haskell | None |
Language | Haskell2010 |
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
- newtype Seed = Seed {}
- createSeed :: String -> Seed
- data Avatar = Avatar {
- color :: Color
- grid :: AvatarGrid
- generateAvatar :: Seed -> Avatar
- scaleAvatar :: Int -> Avatar -> Avatar
- saveAvatar :: Avatar -> FilePath -> IO ()
- convertAvatarToImage :: Avatar -> Image PixelRGB8
- data Color
- getColorValue :: Color -> PixelRGB8
- colorFromSeed :: Seed -> Color
- newtype AvatarGrid = AvatarGrid {
- unAvatarGrid :: [[Bool]]
- showGrid :: [[Bool]] -> String
- generateAvatarGrid :: Seed -> AvatarGrid
- scaleList :: Int -> [a] -> [a]
Types
Seed
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.
createSeed :: String -> Seed Source #
Creates a seed from a given String.
>>>
createSeed "Hello"
Seed {unSeed = "8b1a9953c4611296a827abf8c47804d7"}
Avatar
A generated avatar.
Avatar | |
|
generateAvatar :: Seed -> Avatar Source #
Generates an avatar from the given seed.
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
Color
A color for an avatar.
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.
AvatarGrid | |
|
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"}
██ ██ ██ ██ ██ █ █ █ █ ██ ██ ████████ █ ██ █ █ █