2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1 +1,14 @@
The task is to display a series of vertical color bars across the width of the display. The color bars should either use the system palette, or the sequence of colors: Black, Red, Green, Blue, Magenta, Cyan, Yellow, White.
;Task:
Display a series of vertical color bars across the width of the display.
The color bars should either use:
:::*   the system palette,   or
:::*   the sequence of colors:
::::::*   black
::::::*   red
::::::*   green
::::::*   magenta
::::::*   cyan
::::::*   yellow
::::::*   white
<br>

View file

@ -0,0 +1,38 @@
#!/usr/bin/env stack
-- stack --resolver lts-7.0 --install-ghc runghc --package vty -- -threaded
import Graphics.Vty
colorBars :: Int -> [(Int, Attr)] -> Image
colorBars h bars = horizCat $ map colorBar bars
where colorBar (w, attr) = charFill attr ' ' w h
barWidths :: Int -> Int -> [Int]
barWidths nBars totalWidth = map barWidth [0..nBars-1]
where fracWidth = fromIntegral totalWidth / fromIntegral nBars
barWidth n =
let n' = fromIntegral n :: Double
in floor ((n' + 1) * fracWidth) - floor (n' * fracWidth)
barImage :: Int -> Int -> Image
barImage w h = colorBars h $ zip (barWidths nBars w) attrs
where attrs = map color2attr colors
nBars = length colors
colors = [black, brightRed, brightGreen, brightMagenta, brightCyan, brightYellow, brightWhite]
color2attr c = Attr Default Default (SetTo c)
main = do
cfg <- standardIOConfig
vty <- mkVty cfg
let output = outputIface vty
bounds <- displayBounds output
let showBars (w,h) = do
let img = barImage w h
pic = picForImage img
update vty pic
e <- nextEvent vty
case e of
EvResize w' h' -> showBars (w',h')
_ -> return ()
showBars bounds
shutdown vty

View file

@ -0,0 +1,51 @@
-- Before you can install the SFML Haskell library, you need to install
-- the CSFML C library. (For example, "brew install csfml" on OS X.)
-- This program runs in fullscreen mode.
-- Press any key or mouse button to exit.
import Control.Exception
import SFML.Graphics
import SFML.SFResource
import SFML.Window hiding (width, height)
withResource :: SFResource a => IO a -> (a -> IO b) -> IO b
withResource acquire = bracket acquire destroy
withResources :: SFResource a => IO [a] -> ([a] -> IO b) -> IO b
withResources acquire = bracket acquire (mapM_ destroy)
colors :: [Color]
colors = [black, red, green, magenta, cyan, yellow, white]
makeBar :: (Float, Float) -> (Color, Int) -> IO RectangleShape
makeBar (barWidth, height) (c, i) = do
bar <- err $ createRectangleShape
setPosition bar $ Vec2f (fromIntegral i * barWidth) 0
setSize bar $ Vec2f barWidth height
setFillColor bar c
return bar
barSize :: VideoMode -> (Float, Float)
barSize (VideoMode w h _ ) = ( fromIntegral w / fromIntegral (length colors)
, fromIntegral h )
loop :: RenderWindow -> [RectangleShape] -> IO ()
loop wnd bars = do
mapM_ (\x -> drawRectangle wnd x Nothing) bars
display wnd
evt <- waitEvent wnd
case evt of
Nothing -> return ()
Just SFEvtClosed -> return ()
Just (SFEvtKeyPressed {}) -> return ()
Just (SFEvtMouseButtonPressed {}) -> return ()
_ -> loop wnd bars
main :: IO ()
main = do
vMode <- getDesktopMode
let wStyle = [SFFullscreen]
withResource (createRenderWindow vMode "color bars" wStyle Nothing) $
\wnd -> withResources (mapM (makeBar $ barSize vMode) $ zip colors [0..]) $
\bars -> loop wnd bars

View file

@ -0,0 +1,14 @@
[string[]]$colors = "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan",
"DarkRed" , "DarkMagenta", "DarkYellow", "Gray",
"DarkGray", "Blue" , "Green" , "Cyan",
"Red" , "Magenta" , "Yellow" , "White"
for ($i = 0; $i -lt 64; $i++)
{
for ($j = 0; $j -lt $colors.Count; $j++)
{
Write-Host (" " * 12) -BackgroundColor $colors[$j] -NoNewline
}
Write-Host
}

View file

@ -1,26 +1,26 @@
/*REXX program displays eight colored vertical bars on the full screen. */
parse value scrsize() with sd sw . /*screen depth,width.*/
barWidth=sw%8 /*calculate bar width*/
_.=copies('db'x,barWidth) /*the bar, full width*/
_.8=left(_.,barWidth-1) /*last bar width. */
$ = x2c('1b5b73') || x2c('1b5b313b33376d') /* preamble, header. */
hdr.1 = x2c('1b5b303b33306d') /* the color black. */
hdr.2 = x2c('1b5b313b33316d') /* the color red. */
hdr.3 = x2c('1b5b313b33326d') /* the color green. */
hdr.4 = x2c('1b5b313b33346d') /* the color blue. */
hdr.5 = x2c('1b5b313b33356d') /* the color magenta.*/
hdr.6 = x2c('1b5b313b33366d') /* the color cyan. */
hdr.7 = x2c('1b5b313b33336d') /* the color yellow. */
hdr.8 = x2c('1b5b313b33376d') /* the color white. */
tail = x2c('1b5b751b5b303b313b33363b34303b306d') /* epilogue, trailer.*/
/* [↓] last bar width is shrunk.*/
do j=1 for 8 /*build the line, color by color.*/
$=$ || hdr.j || _.j /*append the color header + bar. */
end /*j*/ /* [↑] color order is the list. */
/* [↓] the tail is overkill. */
$=$ || tail /*append the epilogue (trailer). */
/* [↓] show full screen of bars.*/
do k=1 for sd /*SD = screen depth (from above).*/
say $ /*have REXX display line of bars.*/
end /*k*/ /* [↑] Note: SD could be zero.*/
/*stick a fork in it, we're done.*/
/*REXX program displays eight colored vertical bars on a full screen. */
parse value scrsize() with sd sw . /*the screen depth and width. */
barWidth=sw%8 /*calculate the bar width. */
_.=copies('db'x, barWidth) /*the bar, full width. */
_.8=left(_.,barWidth-1) /*the last bar width, less one. */
$ = x2c('1b5b73') || x2c("1b5b313b33376d") /* the preamble, and the header. */
hdr.1 = x2c('1b5b303b33306d') /* " color black. */
hdr.2 = x2c('1b5b313b33316d') /* " color red. */
hdr.3 = x2c('1b5b313b33326d') /* " color green. */
hdr.4 = x2c('1b5b313b33346d') /* " color blue. */
hdr.5 = x2c('1b5b313b33356d') /* " color magenta. */
hdr.6 = x2c('1b5b313b33366d') /* " color cyan. */
hdr.7 = x2c('1b5b313b33336d') /* " color yellow. */
hdr.8 = x2c('1b5b313b33376d') /* " color white. */
tail = x2c('1b5b751b5b303b313b33363b34303b306d') /* " epilogue, and the trailer.*/
/* [↓] last bar width is shrunk. */
do j=1 for 8 /*build the line, color by color. */
$=$ || hdr.j || _.j /*append the color header + bar. */
end /*j*/ /* [↑] color order is the list. */
/* [↓] the tail is overkill. */
$=$ || tail /*append the epilogue (trailer). */
/* [↓] show full screen of bars. */
do k=1 for sd /*SD = screen depth (from above). */
say $ /*have REXX display line of bars. */
end /*k*/ /* [↑] Note: SD could be zero. */
/*stick a fork in it, we're done. */