module Picture where
type Height = Int
type Width = Int
type Picture = (Height, Width, [[Char]])
height :: Picture -> Height
height (h, _, _) = h
width :: Picture -> Width
width (_, w, _) = w
pixel :: Char -> Picture
pixel c = (1, 1, [[c]])
row :: String -> Picture
row r = (1, length r, [r])
blank :: Height -> Width -> Picture
blank h w = (h, w, blanks)
where
blanks = replicate h (replicate w ' ')
above :: Picture -> Picture -> Picture
(h, w, css) `above` (h', w', css')
| w == w' = (h + h', w, css ++ css')
| otherwise = error "above: different widths"
stack :: [Picture] -> Picture
stack = foldr1 above
beside :: Picture -> Picture -> Picture
(h, w, css) `beside` (h', w', css')
| h == h' = (h, w + w', zipWith (++) css css')
| otherwise = error "beside: different heights"
spread :: [Picture] -> Picture
spread = foldr1 beside
tile :: [[Picture]] -> Picture
tile = stack . map spread
showPic :: Picture -> String
showPic (_, _, css) = unlines css