Main.hs 959 B

1234567891011121314151617181920212223242526272829303132333435
  1. {-# LANGUAGE MultiWayIf #-}
  2. module Main where
  3. import Control.Monad (forM_)
  4. import Image.Pixels
  5. import qualified System.Random as R
  6. glyph :: FilePath -> IO ()
  7. glyph fp = do
  8. rs <- fmap R.randoms R.newStdGen
  9. let (w, h) = (3, 3)
  10. (fw, fh) = (w * 2 - 1, h * 2 - 1)
  11. let img = scaleUp 16 $ image black (fw + 2) (fh + 2) $ do
  12. forM_ (zip [1..fw ] (cycle [True,False])) $ \ (x, xConn) ->
  13. forM_ (zip [1..fh] (cycle [True,False])) $ \ (y, yConn) ->
  14. let color = if | xConn && yConn ->
  15. white
  16. | xConn || yConn ->
  17. if rs !! fromIntegral (x + fw * y)
  18. then black
  19. else white
  20. | otherwise ->
  21. black
  22. in draw color x y
  23. savePBM fp img
  24. main :: IO ()
  25. main = do
  26. forM_ [0..15] $ \ n -> do
  27. glyph ("glyph" ++ show n ++ ".pbm")