Created
October 1, 2019 04:07
-
-
Save ChrisPenner/ecc365d1cde2efaac0cfb164eed03f49 to your computer and use it in GitHub Desktop.
Cofree animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Lib where | |
| import Control.Comonad.Cofree | |
| import Control.Monad.Reader | |
| import Control.Concurrent | |
| drawBar :: Float -> IO () | |
| drawBar n = putStrLn (replicate (ceiling n) '#') | |
| type Animation = Cofree (Reader Float) Float | |
| animation :: Cofree (Reader Float) Float | |
| animation = unfold go 0 | |
| where | |
| go :: Float -> (Float, Reader Float Float) | |
| go n = ((1 + sin n) * 10, asks (+ n)) | |
| loop :: Animation -> IO () | |
| loop (a :< next) = do | |
| drawBar a | |
| threadDelay 10000 | |
| loop (runReader next 0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment