-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtime-gif.hs
53 lines (39 loc) · 1.29 KB
/
time-gif.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import GifStream
import Numbers
import System.Random
import Data.Time.Clock
import Data.Time.LocalTime
import Data.List
import qualified Data.ByteString as B
import qualified Data.Vector.Storable as V
delay = 1000000 -- in µs
port = 5002
width = 33
height = 7
zoom = 4
main :: IO ()
main = server port delay logic
logic :: IO () -> IO Char -> (Frame -> IO ()) -> IO ()
logic wait getInput sendFrame = go
where
go = do
now <- getCurrentTime
let (TimeOfDay h m s) = localTimeOfDay $ utcToLocalTime utc now
let display = scale zoom $ map (map colorize) $ framing $
foldr1 (zipWith (++)) $ map (numbers !!) $ intersperse 10
[ h `div` 10, h `mod` 10, 11
, m `div` 10, m `mod` 10, 11
, (floor s) `div` 10, (floor s) `mod` 10
]
let w = length $ head display
let h = length display
let img = frame (delay `div` 10000) (B.concat $ map mapLine display, w, h)
sendFrame (img, w, h)
wait
go
framing xs = map (preappend 0) $ preappend (take (length (xs !! 0)) (repeat 0)) xs
mapLine x = B.pack $ map (\(r,g,b) -> fromIntegral $ 16*r+4*g+b) x
preappend x xs = x : xs ++ [x]
colorize 1 = (3,3,3)
colorize 0 = (0,0,0)
scale z frame = concatMap (replicate z) (map (concatMap (replicate z)) frame)