Last active
December 15, 2016 19:07
-
-
Save CatherineH/e2c1a00791111bbc006fe9d1e9fce4e4 to your computer and use it in GitHub Desktop.
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 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