module Main where

import qualified Data.ByteString.Lazy as BS
import Image.VK

mkImage :: VKImage -> IO ()
mkImage img = do
  let VKMeta (w, h) = vkMeta img
  putStr "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\""
  putStrLn $ concat [" width=\"", show w, "\" height=\"", show h, "\">" ]
  mapM_ pLine (vkLines img)
  putStrLn "</svg>"
  where pLine [] = return ()
        pLine [x] = return ()
        pLine ((x,y):a@(x',y'):as) = do
          putStrLn $ concat [ "<line x1=\""
                            , show x
                            , "\" y1=\""
                            , show y
                            , "\" x2=\""
                            , show x'
                            , "\" y2=\""
                            , show y'
                            , "\" stroke=\"black\" stroke-width=\"2\" />"
                            ]
          pLine (a:as)

main :: IO ()
main = do
  cs <- BS.getContents
  case decode cs of
    Left err -> putStrLn err
    Right vk -> mkImage vk
