VMPZ6XVHIWAVIWHZ6WEXEZRZLDPQN7NWJIW3YHG5YRH4I2BXXMBAC CHFKQM47XREZBR5LKV6J4G7FYXQD3SA5XGDAY7P4JF6IBCMUGG3QC 6QAAR2VPKVD3II6SKKLQBHRYOFX4NHA6HGJMBMFRPQCVE5OLKWJQC F3QBAH24YMFWMCA3KJBBUWQTCVTCZW7ZWMSCNWJVQVSLK7BG7TGQC NQEZG66FQWQQOOYXN2GK7MHIQH25QBBNKE37GGDJBCHCSKWJZABQC 7QP2V7ZBVZ7SKQ3SYV6NYA7V77G3Y7GF5V6EPIXLIYFSMFRWR4VAC LDXV64JUWYYYPCV6CWMGS3EFX4ZSO7TQ6X327EOQWC5Z6W75UMXQC VHUL3O55RPR6QD7IXPMJFWI5EOXHQYAMHCLP2FYAULPAOAWUVQ7QC O7B34AE2RCSSUKPDKL6VRLOAGH3OYXD6VAI6C6KHZMA7RWUMN2MQC K7KUOYE2VONTDGZ6BIAGA3F7RYQEBNTY3LQOYQM4FH3MOUTLBL6AC EDJU6E3O44JB425LUX6H5IDTRUSXPUGUNYF2NJBP6VW2GZKCWG6QC io 19State { play = True , algo = Terra , center = 0 , focus = 0 , rand = drop size r }(noise r $ verse size)
let z = maybe (error "need to provide size as first argument") read $ args ? 0go (args ? 1) 19State { play = True , algo = Terra , center = 0 , focus = 0 , rand = drop z r }(noise r $ verse z)where
| KeyPress 'q' <- e = Left ()| KeyPress 'H' <- e = Right (s { center = shift v 1 H $ center s } , v)| KeyPress 'J' <- e = Right (s { center = shift v 1 N $ center s } , v)| KeyPress 'K' <- e = Right (s { center = shift v 1 I $ center s } , v)| KeyPress 'L' <- e = Right (s { center = shift v 1 L $ center s } , v)| KeyPress 'h' <- e = Right (s { focus = shift v 1 H $ focus s } , v)| KeyPress 'j' <- e = Right (s { focus = shift v 1 N $ focus s } , v)| KeyPress 'k' <- e = Right (s { focus = shift v 1 I $ focus s } , v)| KeyPress 'l' <- e = Right (s { focus = shift v 1 L $ focus s } , v)| KeyPress 'r' <- e = Right (s { rand = drop (V.length $ nodes v) $ rand s } , noise (rand s) v )| KeyPress 's' <- e = Right (s { algo = forw $ algo s } , v)| KeyPress 'S' <- e = Right (s { algo = back $ algo s } , v)| KeyPress 'p' <- e = Right (s { play = not $ play s } , v)| KeyPress '.' <- e = Right (s { play = False } , v')| KeyPress '_' <- e = Right (s , v { nodes = V.map (\n -> n { atom = prev $ atom n }) $ nodes v })| KeyPress '+' <- e = Right (s , v { nodes = V.map (\n -> n { atom = next $ atom n }) $ nodes v })| KeyPress '-' <- e = Right (s , upd prev (focus s) v)| KeyPress '=' <- e = Right (s , upd next (focus s) v)| KeyPress c <- e , isDigit c , n <- digitToInt c , n <= fromEnum (maxBound :: Hex) = Right (s , upd (const $ toEnum n) (focus s) v)| KeyPress c <- e , Just n <- elemIndex c ")!@#$%^&*(" , n <= fromEnum (maxBound :: Algo) = Right (s { algo = toEnum n } , v)| play s, Tick <- e = Right (s , v')
| ATG.KeyPress 'q' <- e = Left ()| ATG.KeyPress 'H' <- e = Right (s { center = shift v 1 H $ center s } , v)| ATG.KeyPress 'J' <- e = Right (s { center = shift v 1 N $ center s } , v)| ATG.KeyPress 'K' <- e = Right (s { center = shift v 1 I $ center s } , v)| ATG.KeyPress 'L' <- e = Right (s { center = shift v 1 L $ center s } , v)| ATG.KeyPress 'h' <- e = Right (s { focus = shift v 1 H $ focus s } , v)| ATG.KeyPress 'j' <- e = Right (s { focus = shift v 1 N $ focus s } , v)| ATG.KeyPress 'k' <- e = Right (s { focus = shift v 1 I $ focus s } , v)| ATG.KeyPress 'l' <- e = Right (s { focus = shift v 1 L $ focus s } , v)| ATG.KeyPress 'r' <- e = Right (s { rand = drop (V.length $ nodes v) $ rand s } , noise (rand s) v )| ATG.KeyPress 's' <- e = Right (s { algo = forw $ algo s } , v)| ATG.KeyPress 'S' <- e = Right (s { algo = back $ algo s } , v)| ATG.KeyPress 'p' <- e = Right (s { play = not $ play s } , v)| ATG.KeyPress '.' <- e = Right (s { play = False } , v')| ATG.KeyPress '_' <- e = Right (s , v { nodes = V.map (\n -> n { atom = prev $ atom n }) $ nodes v })| ATG.KeyPress '+' <- e = Right (s , v { nodes = V.map (\n -> n { atom = next $ atom n }) $ nodes v })| ATG.KeyPress '-' <- e = Right (s , upd prev (focus s) v)| ATG.KeyPress '=' <- e = Right (s , upd next (focus s) v)| ATG.KeyPress c <- e , isDigit c , n <- digitToInt c , n <= fromEnum (maxBound :: Hex) = Right (s { algo = toEnum n } , v)| ATG.KeyPress c <- e , Just n <- elemIndex c ")!@#$%^&*(" , n <= fromEnum (maxBound :: Algo) = Right (s , upd (const $ toEnum n) (focus s) v)| play s , ATG.Tick <- e = Right (s , v')
draw :: GEnv -> (State,Verse Hex) -> Planedraw e (s,v) = centerFull e hex & (1,1) % vcat[ word " cells demo" # color White Vivid, vcat $ select <$> total
draw :: ATG.GEnv -> (State,Verse Hex) -> ATG.Planedraw e (s,v) = ATG.centerFull e hex ATG.& (1,1) ATG.% ATG.vcat[ ATG.word " cells demo" ATG.# ATG.color ATG.White ATG.Vivid, ATG.vcat $ select <$> total
select :: Algo -> Planeselect x = hcat[ word (show $ fromEnum x) # color (if algo s == x then Yellow else White) Dull, word " ", word (toLower <$> show x) # color (if algo s == x then Cyan else White) Dull
select :: Algo -> ATG.Planeselect x = ATG.hcat[ ATG.word (show $ fromEnum x) ATG.# ATG.color (if algo s == x then ATG.Yellow else ATG.White) ATG.Dull, ATG.word " ", ATG.word (toLower <$> show x) ATG.# ATG.color (if algo s == x then ATG.Cyan else ATG.White) ATG.Dull
| n == focus s = (c , ATGP.paletteColorCell k $ ATGP.creaCell $ intToDigit $ fromEnum h)| otherwise = (c , ATGP.paletteColorCell k $ ATGP.creaCell $ " ·~+=≠co" !! fromEnum h)
| n == focus s = (c , ATG.paletteColorCell k $ ATG.creaCell $ intToDigit $ fromEnum h)| otherwise = (c , ATG.paletteColorCell k $ ATG.creaCell $ " ·~+=≠co" !! fromEnum h)
| 0 <- fromEnum h , play s = xterm6LevelRGB 0 1 0| 1 <- fromEnum h , play s = xterm6LevelRGB 0 1 1| 2 <- fromEnum h , play s = xterm6LevelRGB 1 1 2| 3 <- fromEnum h , play s = xterm6LevelRGB 2 1 3| 4 <- fromEnum h , play s = xterm6LevelRGB 3 1 4| 5 <- fromEnum h , play s = xterm6LevelRGB 4 2 5| 6 <- fromEnum h , play s = xterm6LevelRGB 5 3 5| 7 <- fromEnum h , play s = xterm6LevelRGB 5 4 5| 0 <- fromEnum h = xterm24LevelGray 2| 1 <- fromEnum h = xterm24LevelGray 5| 2 <- fromEnum h = xterm24LevelGray 8| 3 <- fromEnum h = xterm24LevelGray 11| 4 <- fromEnum h = xterm24LevelGray 14| 5 <- fromEnum h = xterm24LevelGray 17| 6 <- fromEnum h = xterm24LevelGray 23| 7 <- fromEnum h = xterm24LevelGray 23| otherwise = xterm24LevelGray 0
| 0 <- fromEnum h , play s = ATG.xterm6LevelRGB 0 1 0| 1 <- fromEnum h , play s = ATG.xterm6LevelRGB 0 1 1| 2 <- fromEnum h , play s = ATG.xterm6LevelRGB 1 1 2| 3 <- fromEnum h , play s = ATG.xterm6LevelRGB 2 1 3| 4 <- fromEnum h , play s = ATG.xterm6LevelRGB 3 1 4| 5 <- fromEnum h , play s = ATG.xterm6LevelRGB 4 2 5| 6 <- fromEnum h , play s = ATG.xterm6LevelRGB 5 3 5| 7 <- fromEnum h , play s = ATG.xterm6LevelRGB 5 4 5| 0 <- fromEnum h = ATG.xterm24LevelGray 2| 1 <- fromEnum h = ATG.xterm24LevelGray 5| 2 <- fromEnum h = ATG.xterm24LevelGray 8| 3 <- fromEnum h = ATG.xterm24LevelGray 11| 4 <- fromEnum h = ATG.xterm24LevelGray 14| 5 <- fromEnum h = ATG.xterm24LevelGray 17| 6 <- fromEnum h = ATG.xterm24LevelGray 23| 7 <- fromEnum h = ATG.xterm24LevelGray 23| otherwise = ATG.xterm24LevelGray 0instance Brick.Interface State Hex wherelogic :: Brick.BrickEvent () () -> (State,Verse Hex) -> Maybe (State,Verse Hex)logic ev (s,v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'q') []) <- ev = Nothing| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'H') []) <- ev = Just (s { center = shift v 1 H $ center s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'J') []) <- ev = Just (s { center = shift v 1 N $ center s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'K') []) <- ev = Just (s { center = shift v 1 I $ center s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'L') []) <- ev = Just (s { center = shift v 1 L $ center s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'h') []) <- ev = Just (s { focus = shift v 1 H $ focus s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'j') []) <- ev = Just (s { focus = shift v 1 N $ focus s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'k') []) <- ev = Just (s { focus = shift v 1 I $ focus s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'l') []) <- ev = Just (s { focus = shift v 1 L $ focus s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'r') []) <- ev = Just (s { rand = drop (V.length $ nodes v) $ rand s } , noise (rand s) v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 's') []) <- ev = Just (s { algo = forw $ algo s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'S') []) <- ev = Just (s { algo = back $ algo s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar 'p') []) <- ev = Just (s { play = not $ play s } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar '.') []) <- ev = Just (s { play = False } , v')| Brick.VtyEvent (Vty.EvKey (Vty.KChar '_') []) <- ev = Just (s , v { nodes = (\n -> n { atom = prev $ atom n }) <$> nodes v })| Brick.VtyEvent (Vty.EvKey (Vty.KChar '+') []) <- ev = Just (s , v { nodes = (\n -> n { atom = next $ atom n }) <$> nodes v })| Brick.VtyEvent (Vty.EvKey (Vty.KChar '-') []) <- ev = Just (s , upd prev (focus s) v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar '=') []) <- ev = Just (s , upd next (focus s) v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar c) []) <- ev , isDigit c , n <- digitToInt c , n <= fromEnum (maxBound :: Hex) = Just (s { algo = toEnum n } , v)| Brick.VtyEvent (Vty.EvKey (Vty.KChar c) []) <- ev , Just n <- elemIndex c ")!@#$%^&*(" , n <= fromEnum (maxBound :: Algo) = Just (s , upd (const $ toEnum n) (focus s) v)| Brick.AppEvent () <- ev , play s = Just (s , v') -- tick| otherwise = Just (s , v)wherev' :: Verse Hexv' = sim cells s vdraw :: (State,Verse Hex) -> [Brick.Widget ()]draw (s,v) =[ Brick.translateBy (Brick.Location (2,0)) $ Brick.vCenterLayer ui, Brick.center hex]where
size :: Intsize = radius vdefaultStyle :: Brick.Widget a -> Brick.Widget adefaultStyle = Brick.withDefAttr (Brick.attrName "solid"). Brick.withBorderStyle Brick.unicodeRounded. Brick.modifyDefAttr (flip Vty.withForeColor Vty.brightBlack). Brick.border. Brick.modifyDefAttr (flip Vty.withForeColor Vty.brightWhite). Brick.padLeftRight 1ui :: Brick.Widget ()ui = defaultStyle $ Brick.vBox $ Brick.str "cells demo" : (Brick.raw . select <$> total)whereselect :: Algo -> Vty.Imageselect x = Vty.horizCat[ Vty.string (coloured x Vty.yellow) (show $ fromEnum x), Vty.string Vty.defAttr " ", Vty.string (coloured x Vty.cyan) (toLower <$> show x)]coloured :: Algo -> Vty.Color -> Vty.Attrcoloured x c| algo s == x = Vty.withForeColor Vty.defAttr c| otherwise = Vty.withForeColor Vty.defAttr Vty.brightBlack-- hex :: Vty.Image-- hex = Vty.vertCat [ Vty.horizCat [ M.findWithDefault (Vty.char Vty.defAttr ' ') (row,col) vtycellMap | col <- [0 .. 4*size] ] | row <- [0 .. 2*size] ]hex :: Brick.Widget ()hex = Brick.Widget Brick.Greedy Brick.Greedy $ doctx <- Brick.getContextBrick.render $ Brick.raw $ img ctxwhereimg ctx = Vty.vertCat [ Vty.horizCat [ M.findWithDefault (Vty.char Vty.defAttr ' ') (row,col) vtycellMap | col <- cols ] | row <- rows ]wheretw = Brick.availWidth ctxth = Brick.availHeight ctxiw = 4*size + 1ih = 2*size + 1dx = max 0 (div (iw - tw) 2)dy = max 0 (div (ih - th) 2)cols = [dx .. min (dx + tw - 1) (iw - 1)]rows = [dy .. min (dy + th - 1) (ih - 1)]vtycellMap :: M.Map (Int,Int) Vty.ImagevtycellMap = M.fromList [ ((size - y , 2*(x+size)+y) , Vty.char attr ch) | x <- [-size..size] , y <- [-size..size] , abs (x+y) <= size , let (attr,ch) = vtycell x y ]vtycell :: Int -> Int -> (Vty.Attr,Char)vtycell x y = (Vty.withForeColor Vty.defAttr col , ch)whereh = get v nn = shift v mx L . shift v my I $ coordToIndex v (mod (x - div y size * size) (3*size) , mod y size)(mx,my) = indexToCoord v $ center sch | n == focus s = intToDigit $ fromEnum h| otherwise = " ·~+=≠co" !! fromEnum hcol = k (fromEnum h)k :: Int -> Vty.Colork i| play s , 0 <- i = xrgb 0 1 0| play s , 1 <- i = xrgb 0 1 1| play s , 2 <- i = xrgb 1 1 2| play s , 3 <- i = xrgb 2 1 3| play s , 4 <- i = xrgb 3 1 4| play s , 5 <- i = xrgb 4 2 5| play s , 6 <- i = xrgb 5 3 5| play s , 7 <- i = xrgb 5 4 5| 0 <- i = xgray 2| 1 <- i = xgray 5| 2 <- i = xgray 8| 3 <- i = xgray 11| 4 <- i = xgray 14| 5 <- i = xgray 17| 6 <- i = xgray 23| 7 <- i = xgray 23| otherwise = xgray 0-- xterm 6-level RGB cube (colors 16–231)xrgb :: Int -> Int -> Int -> Vty.Colorxrgb r g b = Vty.Color240 $ fromIntegral (36*r + 6*g + b)-- xterm 24-level greyscale ramp (colors 232–255)xgray :: Int -> Vty.Colorxgray n = Vty.Color240 $ fromIntegral (216 + n)
source-repository-packagetype: gitlocation: git@gitlab.com:jrvieira1/ansi-terminal-game.gitbranch: master