Skip to content

Instantly share code, notes, and snippets.

@CatherineH
Last active December 15, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CatherineH/e2c1a00791111bbc006fe9d1e9fce4e4 to your computer and use it in GitHub Desktop.
Save CatherineH/e2c1a00791111bbc006fe9d1e9fce4e4 to your computer and use it in GitHub Desktop.
import UI.NCurses
import Control.Monad (forM_)
import Data.Int
num_accross = 24
num_down = 9
colors = [ColorMagenta, ColorRed, ColorYellow, ColorGreen, ColorBlue, ColorCyan, ColorWhite, ColorBlack]
main = runCurses $ do
w <- defaultWindow
forM_ [(x,y) | x<-[0..num_accross], y<-[0..num_down]] $ \(x,y) ->
do
let colIndex = x*(num_down+1)+y+1
let my_color = Color (fromIntegral colIndex :: Int16)
defineColor my_color (x*36) 0 (y*110)
cid <- newColorID my_color ColorBlack (toInteger colIndex)
updateWindow w $ do
setColor cid
moveCursor (fromIntegral y) (fromIntegral x)
drawString "■"
render
waitFor w (\ev -> ev == EventCharacter 'q' || ev == EventCharacter 'Q')
waitFor :: Window -> (Event -> Bool) -> Curses ()
waitFor w p = loop where
loop = do
ev <- getEvent w Nothing
case ev of
Nothing -> loop
Just ev' -> if p ev' then return () else loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment