Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Calendar where
  2.  
  3. import Control.Monad.Eff
  4. import Graphics.Canvas hiding (translate)
  5. import Prelude
  6. import Data.Array
  7. import Data.Foldable
  8. import Data.Traversable
  9.  
  10. background = "#000000"
  11.  
  12. type Position = { x :: Number, y :: Number }
  13.  
  14. drawDay :: forall eff. Rectangle -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
  15. drawDay r ctx = do
  16.   setFillStyle "#92b5c8" ctx
  17.   setShadowBlur 0 ctx
  18.   fillRect ctx r
  19.   setFont "18px Arial" ctx
  20.   setFillStyle "#FFFFFF" ctx
  21.   fillText ctx "10" (r.x+4) (r.y+21)
  22.  
  23. dayRect pos n = {x: pos.x + 31 * n, y: pos.y, w: 30, h: 30}
  24.  
  25. combineArray :: forall f a. (Applicative f) => [f a] -> f [a]
  26. combineArray [] = pure []
  27. combineArray (x : xs) = (:) <$> x <*> combineArray xs
  28.  
  29. drawNDays :: forall eff. Number -> Position -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
  30. drawNDays n pos ctx = traverse (\ddd -> drawDay (dayRect pos ddd) ctx) (1 .. 7)
  31.  
  32. drawWeek :: forall eff. Position -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
  33. drawWeek pos ctx = drawNDays 7 pos ctx
  34.  
  35. drawNWeeks :: forall eff. Number -> Position -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
  36. drawNWeeks 1 pos ctx = drawWeek pos ctx
  37. drawNWeeks n pos ctx = do
  38.  drawWeek {x: pos.x, y: pos.y + ((n-1)*31)} ctx
  39.  drawNWeeks (n-1) pos ctx
  40.  
  41. drawMonth :: forall eff. Position -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
  42. drawMonth pos ctx = do
  43.     drawNWeeks 4 pos ctx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement