Skip to content
Andy Gill edited this page Dec 6, 2019 · 9 revisions

{-# LANGUAGE OverloadedStrings #-}
module Main where

import qualified Data.Vector.Unboxed as V
import           Graphics.Blank

main :: IO ()
main = do
    blankCanvas 3000 $ \ context -> do
        url <- staticURL context "type/jpeg" "images/House.jpg"
        ImageData w h v <- send context $ do
            img <- newImage url
            drawImage(img,[50,50])
            getImageData(50,50, width img, height img)
        
        let group4 (a:b:c:d:xs) = (a,b,c,d) : group4 xs
            group4 _            = []
        
        let v' = V.fromList
              $ concat
              $ [ let brightness = round
                                 ( 0.34 * fromIntegral r 
                                 + 0.5 * fromIntegral g
                                 + 0.16 * fromIntegral b :: Double)
                  in [brightness,brightness,brightness,a] 
                | (r,g,b,a) <- group4 $ V.toList $ v
                ]
        
        send context $ do
            putImageData (ImageData w h v', [100,100])
Clone this wiki locally