Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Last active November 20, 2016 01:05
Show Gist options
  • Save sleexyz/72598fa7790dea4e93bc42b1d251d016 to your computer and use it in GitHub Desktop.
Save sleexyz/72598fa7790dea4e93bc42b1d251d016 to your computer and use it in GitHub Desktop.
visualize bytebeat
{-# LANGUAGE BangPatterns #-}
-- | Visualize bytebeat. currently doesn't print fast enough...
module Main where
import Control.Monad
import Data.Bits
import qualified Data.Char as C
import Data.List
import System.IO
import System.Environment
import qualified Data.ByteString as BS
visualize :: Int -> String
visualize !byte = (mconcat $ replicate byte " ") ++ "#"
visualizeBits :: Int -> Int -> String
visualizeBits len byte = foldr f "" [1..len] where
f n str = c : str where
c = if testBit byte n then '█' else ' '
foo :: Handle -> String -> IO ()
foo h str = do
putStr $ mconcat $ (visualizeBits 8 . C.ord) <$> str
hPutStr h str
main :: IO ()
main = do
(fifopath:_) <- getArgs
h <- openFile fifopath WriteMode
forever $ (replicateM 256 getChar) >>= foo h
@sleexyz
Copy link
Author

sleexyz commented Nov 19, 2016

ls bytebeat.hs vis.hs | entr -cr bash -c "runghc bytebeat.hs | tee >(aplay > /dev/null) | runghc vis.hs"
ls bytebeat.hs vis.hs | entr -cr bash -c "runghc bytebeat.hs | runghc vis.hs >(aplay &> /dev/null)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment