Skip to content

Instantly share code, notes, and snippets.

@possan
Created May 28, 2013 18:06
Show Gist options
  • Save possan/5664755 to your computer and use it in GitHub Desktop.
Save possan/5664755 to your computer and use it in GitHub Desktop.
-- haskell plasma attempt
-- compile with: ghc plasma.hs
-- run: plasma 80 50
import Data.Maybe
import Data.List
import System.Posix.Unistd
import System.Environment
coordValue :: Float -> Float -> Float -> Float
coordValue x y t =
3.5 + (3.5 * cos((sin x) + 0.2 * x + 0.6 * (cos (y * 3)) + 0.5 * y + t + 0.7 * (sin (x + t)) + 0.2 * (cos (t + (y * 4) + x * 3))))
drawCol :: Float -> Float -> Float -> String
drawCol y t x =
[arr !! (floor v)]
where
v = (coordValue (x / 10) (y / 10) t)
arr = " .:+o#$&"
drawRow :: Float -> Float -> Float -> String
drawRow w t y =
(foldl1 (++) (fmap (drawCol y t) [0..w])) ++ "\n"
drawFrame :: Float -> Float -> Float -> String
drawFrame w h t =
"\27[H" ++ (foldl1 (++) (fmap (drawRow w t) [0..h]))
frloop :: Float -> Float -> Float -> IO ()
frloop w h t = do
putStrLn (drawFrame w h t)
usleep 10000
frloop w h (t + 0.1)
run :: Float -> Float -> IO ()
run w h = do
putStrLn "\27[2J"
frloop w h 0.0
main :: IO ()
main = do
args <- getArgs
case args of
[w, h] -> run ((read w) :: Float) ((read h) :: Float)
_ -> putStrLn "syntax: ./plasma [columns] [rows]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment