Colour bars/Display: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added PicoLisp)
Line 1: Line 1:
{{task}}
{{task}}
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.
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.

=={{header|PicoLisp}}==
{{trans|UNIX Shell}}
<lang PicoLisp>(call 'clear)

(let Width (in '(tput cols) (read))
(do (in '(tput lines) (read))
(for B (range 0 7)
(call 'tput 'setab B)
(space (/ Width 8)) )
(prinl) ) )

(call 'tput 'sgr0) # reset</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==

Revision as of 18:16, 31 May 2011

Task
Colour bars/Display
You are encouraged to solve this task according to the task description, using any language you may know.

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.

PicoLisp

Translation of: UNIX Shell

<lang PicoLisp>(call 'clear)

(let Width (in '(tput cols) (read))

  (do (in '(tput lines) (read))
     (for B (range 0 7)
        (call 'tput 'setab B)
        (space (/ Width 8)) )
     (prinl) ) )

(call 'tput 'sgr0) # reset</lang>

Tcl

Library: Tk

<lang tcl>package require Tcl 8.5 package require Tk 8.5

wm attributes . -fullscreen 1 pack [canvas .c] -fill both -expand 1 set colors {black red green blue magenta cyan yellow white}

for {set x 0} {$x < [winfo screenwidth c]} {incr x 8} {

   .c create rectangle $x 0 [expr {$x+7}] [winfo screenheight c] \
           -fill [lindex $colors 0] -outline {}
   set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]

}</lang>

UNIX Shell

<lang sh>#!/bin/sh clear WIDTH=`tput cols` HEIGHT=`tput lines` NUMBARS=8 BARWIDTH=`expr $WIDTH / $NUMBARS`

l="1" # Set the line counter to 1 while [ "$l" -lt $HEIGHT ]; do

 b="0"    # Bar counter
 while [ "$b" -lt $NUMBARS ]; do
   tput setab $b
   s="0"
   while [ "$s" -lt $BARWIDTH ]; do
     echo -n " "
     s=`expr $s + 1`
   done
   b=`expr $b + 1`
 done
 echo    # newline
 l=`expr $l + 1`

done

tput sgr0 # reset</lang>

ZX Spectrum Basic

<lang basic>10 REM The ZX Spectrum display is 32 columns wide, so we have 8 columns of 4 spaces 20 FOR r=0 TO 20: REM There are 21 rows 30 FOR c=0 TO 7: REM We use the native colour sequence here 40 PAPER c: REM set the background colour for the spaces to be printed 50 PRINT " ";: REM four spaces, the semicolon prevents newline 60 NEXT c 70 REM at this point the cursor has wrapped, so we don't need a newline 80 NEXT r</lang>