Print a sine wave to the terminal.
Last active
November 4, 2017 08:40
-
-
Save wzhd/0f16475be5c975341e45f5d6c859ee02 to your computer and use it in GitHub Desktop.
console-wave
This file contains 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
dist | |
cabal-dev | |
*.o | |
*.hi | |
*.chi | |
*.chs.h | |
.virtualenv | |
.hsenv | |
.cabal-sandbox/ | |
cabal.sandbox.config | |
cabal.config |
This file contains 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
import Control.Concurrent (threadDelay) | |
putStrs :: [String] -> IO () | |
putStrs (l:ls) = do | |
putStrLn l | |
threadDelay 50000 | |
putStrs ls | |
plotLines :: [Int] -> [String] | |
plotLines (x0:x1:xs) = line : plotLines xs | |
where | |
line = map charForPos [0 .. max x0 x1] | |
charForPos :: Int -> Char | |
charForPos pos | |
| and $ map (== pos) [x0, x1] = '█' | |
| x0 == pos = '▀' | |
| x1 == pos = '▄' | |
| otherwise = ' ' | |
f :: Float -> Int | |
f x = round $ 40 + 40 * sin(x / 9) | |
main :: IO() | |
main = putStrs $ plotLines $ map f [1..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment