gdritter repos pixels / master examples / Main.hs
master

Tree @master (Download .tar.gz)

Main.hs @masterraw · history · blame

{-# LANGUAGE MultiWayIf #-}

module Main where

import Control.Monad (forM_)
import Image.Pixels
import qualified System.Random as R

glyph :: FilePath -> IO ()
glyph fp = do
  rs <- fmap R.randoms R.newStdGen

  let (w, h) = (3, 3)
      (fw, fh) = (w * 2 - 1, h * 2 - 1)

  let img = scaleUp 16 $ image black (fw + 2) (fh + 2) $ do
        forM_ (zip [1..fw ] (cycle [True,False])) $ \ (x, xConn) ->
          forM_ (zip [1..fh] (cycle [True,False])) $ \ (y, yConn) ->
          let color = if | xConn && yConn ->
                             white
                         | xConn || yConn ->
                             if rs !! fromIntegral (x + fw * y)
                               then black
                               else white
                         | otherwise ->
                             black
          in draw color x y

  savePBM fp img


main :: IO ()
main = do
  forM_ [0..15] $ \ n -> do
    glyph ("glyph" ++ show n ++ ".pbm")