Colour bars/Display: Difference between revisions
→{{header|AmigaBASIC}}: add screenshot
(Task -- 8th color "blue" is missing from task list -- but present in implementations!) |
(→{{header|AmigaBASIC}}: add screenshot) |
||
(57 intermediate revisions by 23 users not shown) | |||
Line 16:
::::::* white
<br>
=={{header|6502 Assembly}}==
Implemented using Easy6502, this displays a pinstripe using the system palette. There are 16 colors, and the bottom 4 bits of A are the color index.
<syntaxhighlight lang="6502asm">lda #0
tax
tay ;clear regs
;video ram on Easy6502 is four pages ranging from $0200-$0500
loop:
sta $0200,x
sta $0220,x
sta $0240,x
sta $0260,x
sta $0280,x
sta $02A0,x
sta $02C0,x
sta $02E0,x
sta $0300,x
sta $0320,x
sta $0340,x
sta $0360,x
sta $0380,x
sta $03A0,x
sta $03C0,x
sta $03E0,x
sta $0400,x
sta $0420,x
sta $0440,x
sta $0460,x
sta $0480,x
sta $04A0,x
sta $04C0,x
sta $04E0,x
sta $0500,x
sta $0520,x
sta $0540,x
sta $0560,x
sta $0580,x
sta $05A0,x
sta $05C0,x
sta $05E0,x
inx
txa ;effectively increment A
cpx #$20 ;32 columns of video memory
beq exit
jmp loop
exit:
brk ;on easy6502 this terminates a program. </syntaxhighlight>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Main()
BYTE
i,
CH=$02FC, ;Internal hardware value for last key pressed
PALNTSC=$D014, ;To check if PAL or NTSC system is used
PCOLR0=$02C0,PCOLR1=$02C1,
PCOLR2=$02C2,PCOLR3=$02C3,
COLOR0=$02C4,COLOR1=$02C5,
COLOR2=$02C6,COLOR3=$02C7,
COLOR4=$02C8
Graphics(10)
PCOLR0=$04 ;gray
PCOLR1=$00 ;black
IF PALNTSC=15 THEN
PCOLR2=$42 ;red for NTSC
PCOLR3=$C6 ;green for NTSC
COLOR0=$84 ;blue for NTSC
COLOR1=$66 ;magenta for NTSC
COLOR2=$A6 ;cyan for NTSC
COLOR3=$FC ;yellow for NTSC
ELSE
PCOLR2=$22 ;red for PAL
PCOLR3=$B6 ;green for PAL
COLOR0=$74 ;blue for PAL
COLOR1=$48 ;magenta for PAL
COLOR2=$96 ;cyan for PAL
COLOR3=$EC ;yellow for PAL
FI
COLOR4=$0F ;white
FOR i=0 TO 79
DO
Color=i/10+1
Plot(i,0)
DrawTo(i,191)
OD
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Colour_bars_display.png Screenshot from Atari 8-bit computer]
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript3">
package {
Line 48 ⟶ 148:
}
</syntaxhighlight>
=={{header|Ada}}==
{{libheader|SDLAda}}
<
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
Line 100 ⟶ 200:
Window.Finalize;
SDL.Finalise;
end Colour_Bars_Display;</
=={{header|AutoHotkey}}==
{{libheader|GDI+}} (available at http://www.autohotkey.net/~tic/Gdip.ahk)
<
#NoEnv
SetBatchLines, -1
Line 196 ⟶ 296:
Gdip_Shutdown(pToken)
ExitApp
Return</
=={{header|AWK}}==
<
BEGIN {
nrcolors = 8
Line 213 ⟶ 313:
}
}
</syntaxhighlight>
=={{header|BASIC}}==
==={{header|AmigaBASIC}}===
[[File:Amigabasic color bars.png|thumb|Output]]
<syntaxhighlight lang="amigabasic">SCREEN 1,320,200,5,1
WINDOW 2,"Color bars",(0,10)-(297,186),15,1
FOR a=0 TO 300
LINE (a,0)-(a,186),(a+10)/10
NEXT
loop: GOTO loop</syntaxhighlight>
==={{header|Applesoft BASIC}}===
<
2 HOME : GR : FOR I = 1 TO 7
3 READ C(I) : NEXT
4 FOR I = 0 TO 39
5 COLOR= C(I / 5)
6 VLIN 0,39 AT I : NEXT</
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<
SYS "ShowWindow", @hwnd%, SW_MAXIMIZE
VDU 26
Line 246 ⟶ 354:
RECTANGLE FILL C%*W%, 0, W%, H%
NEXT
</syntaxhighlight>
==={{header|
The sequence of colors.
<syntaxhighlight lang="basic">
100 rem Colour bars/Display
110 graphics 0 : graphics cls
120 for i = 0 to 7
130 read r,g,b
140 graphics color r,g,b
150 for j = 0 to 79
160 x = i*80+j
170 graphics moveto x,0
180 graphics lineto x,399
190 next j
200 next i
500 data 0,0,0 : rem black
510 data 100,0,0 : rem red
520 data 0,100,0 : rem green
530 data 0,0,100 : rem blue
540 data 100,0,100 : rem magenta
550 data 0,100,100 : rem cyan
560 data 100,100,0 : rem yellow
570 data 100,100,100 : rem white
</syntaxhighlight>
==={{header|Commodore BASIC}}===
This task achieved only on Commodore computers with color capabilities. The example below tested as-is in VICE on the following machines:
* Commodore 64
Line 256 ⟶ 387:
* Commodore CBM-II (with VIC-II video)
* Commodore SX-64
It will also work well on the VIC-20 if you either omit line 310 or comment (REM) it out as the VIC-20 has only an eight-color palette.
Line 262 ⟶ 392:
This cross-compatibility is achieved by using the PETSCII control codes (CHR$(x)) for changing color, which are generally the same across all platforms, although the system palettes themselves may differ. This is combined with printing a "reverse video" space (solid block) character in the color selected.
<
10
20
25
30
40
50
60
70
75
76
80
90
100
110
280
285
300
305
310
320
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
' Draw the color bars on an 80 x 25 console using the system palette of 16 colors
' i.e. 5 columns per color
Width 80, 25
Shell "cls"
Locate ,, 0 '' turn cursor off
For clr As UInteger = 0 To 15
Color 0, clr
For row As Integer = 1 to 25
Locate row, clr * 5 + 1
Print Space(5);
Next row
Next clr
Sleep
' restore default settings
Locate ,, 1 '' turn cursor on
Color 7, 0 '' white text on black background</syntaxhighlight>
==={{header|FutureBasic}}===
[[File:ColorBarsDisplayFB300.png|right]]
<syntaxhighlight lang="futurebasic">
void local fn DoIt
long index, x = 0
CFArrayRef colors = @[fn ColorBlack,fn ColorRed,
fn ColorGreen,fn ColorBlue,fn ColorMagenta,
fn ColorCyan,fn ColorYellow,fn ColorWhite]
window 1, @"Color bars/Display", (0,0,480,270), NSWindowStyleMaskTitled
pen -1
for index = 0 to len(colors) - 1
rect fill (x,0,60,270), colors[index]
x += 60
next
end fn
fn DoIt
HandleEvents
</syntaxhighlight>
==={{header|Gambas}}===
<syntaxhighlight lang="gambas">Public Sub Form_Open()
Dim iColour As Integer[] = [Color.Black, Color.red, Color.Green, Color.Magenta, Color.Cyan, Color.Yellow, Color.white]
Dim hPanel As Panel
Dim siCount As Short
With Me
.Arrangement = Arrange.Horizontal
.Height = 300
.Width = 400
End With
For siCount = 0 To 6
hpanel = New Panel(Me)
hpanel.Expand = True
hpanel.H = 500
HPanel.Background = iColour[siCount]
Next
End</syntaxhighlight>
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 GRAPHICS LORES 16
110 SET PALETTE BLACK,RED,GREEN,BLUE,MAGENTA,CYAN,YELLOW,WHITE
120 FOR I=1 TO 7
130 CALL BAR(I)
140 NEXT
150 DEF BAR(C)
160 SET INK C
170 PLOT C*160,0;C*160,719;C*160+152,719;C*160+152,0;C*160,0
180 PLOT C*160+16,16,PAINT
190 END DEF</syntaxhighlight>
==={{header|Liberty BASIC}}===
<
colors$="black red green blue pink cyan yellow white"
WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
Line 305 ⟶ 512:
wait
[quit] close #main:end
</
==={{header|Locomotive Basic}}===
[[File:CPC color bars.png|thumb|right]]
Show the default MODE 0 palette (includes two blinking colors at the end):
<syntaxhighlight lang="locobasic">10 MODE 0:BORDER 23
20 FOR x=0 TO 15
30 ORIGIN x*40,0
40 FOR z=0 TO 39 STEP 4:MOVE z,0:DRAW z,400,x:NEXT z
50 NEXT x
60 CALL &bb06 ' wait for key press</syntaxhighlight>
==={{header|PureBasic}}===
Press Enter or Escape to exit the program.
<
color(0) = RGB($00, $00, $00) ;black
color(1) = RGB($FF, $00, $00) ;red
Line 353 ⟶ 556:
Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Return)
CloseScreen()
EndIf</
====Alternate method using console====
<
;Black, Red, Green, Blue, Magenta, Cyan, Yellow, White
Data.i 0, 12, 10, 9, 13, 11, 14, 15
Line 378 ⟶ 581:
ConsoleTitle("Press ENTER to exit"): Input()
CloseConsole()
EndIf</
==={{header|Run BASIC}}===
<
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=4><tr height=70>"
for i = 1 to 8
html "<td width=20 bgcolor='";word$(colors$,i,",");"'</td>"
next i
html "</tr></table>"</
<pre>Output</pre>
[[File:ColorBarRunBasic.png]]
==={{header|SmileBASIC}}===
<syntaxhighlight lang="smilebasic">FOR I=0 TO 7
READ R,G,B
GFILL I*50,0,I*50+49,239,RGB(R,G,B)
NEXT
REPEAT UNTIL BUTTON(0) AND #B
DATA 0,0,0
DATA 255,0,0
DATA 0,255,0
DATA 0,0,255
DATA 255,0,255
DATA 0,255,255
DATA 255,255,0
DATA 255,255,255</syntaxhighlight>
==={{header|TI Basic}}===
<
110 REM with 400 Hz reference tone
120 CALL CLEAR
Line 435 ⟶ 654:
540 NEXT I
590 RETURN
</syntaxhighlight>
==={{header|ZX Spectrum Basic}}===
<
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
Line 445 ⟶ 664:
60 NEXT c
70 REM at this point the cursor has wrapped, so we don't need a newline
80 NEXT r</
=={{header|Befunge}}==
Assuming a terminal with support for ANSI escape sequences, this fills the screen with the colour sequence: black, red, green, blue, magenta, cyan, yellow and white. It then waits for the user to press ''Enter'' before terminating.
<
v_:"P"/"["39*,, :55+/68v
v,,,";1H" ,+*86%+55 ,+*<
73654210v,,\,,,*93"[4m"<
>$:55+%#v_:1-"P"%55+/3g^
39*,,,~@>48*,1-:#v_$"m["</
=={{header|C}}==
Line 461 ⟶ 680:
===Text Mode===
The required functions and structures are in conio.h
<syntaxhighlight lang="c">
#include<conio.h>
Line 494 ⟶ 713:
return 0;
}
</syntaxhighlight>
===Graphics Mode===
The required functions and structures are in graphics.h, conio.h is included for getch().
<syntaxhighlight lang="c">
#include<graphics.h>
#include<conio.h>
Line 521 ⟶ 740:
return 0;
}
</syntaxhighlight>
=={{header|C++}}==
Line 528 ⟶ 747:
file <code>colorbars.h</code>:
<
#define MYWIDGET_H
#include <QWidget>
Line 545 ⟶ 764:
const int colornumber ;
} ;
#endif</
file <code>colorbars.cpp</code>:
<
#include "colorbars.h"
Line 575 ⟶ 794:
xstart += rectwidth + 1 ;
}
}</
file <code>main.cpp</code>:
<
#include "colorbars.h"
Line 588 ⟶ 807:
window.show( ) ;
return app.exec( ) ;
}</
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
PROGRAM-ID. terminal-colour-bars.
Line 643 ⟶ 862:
GOBACK
.</
=={{header|Common Lisp}}==
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil)
(dotimes (i (height scr))
Line 656 ⟶ 875:
(refresh scr)
;; wait for keypress
(get-char scr)))</
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Forms}}
<syntaxhighlight lang="delphi">
unit Colour_barsDisplay;
interface
uses
Winapi.Windows, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Forms;
type
TfmColourBar = class(TForm)
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fmColourBar: TfmColourBar;
Colors: array of TColor = [clblack, clred, clgreen, clblue, clFuchsia, clAqua,
clyellow, clwhite];
implementation
{$R *.dfm}
procedure TfmColourBar.FormPaint(Sender: TObject);
var
w, h, i: Integer;
r: TRect;
begin
w := ClientWidth div length(Colors);
h := ClientHeight;
r := Rect(0, 0, w, h);
with Canvas do
for i := 0 to High(Colors) do
begin
Brush.Color := Colors[i];
FillRect(r);
r.Offset(w, 0);
end;
end;
procedure TfmColourBar.FormResize(Sender: TObject);
begin
Invalidate;
end;
end.</syntaxhighlight>
Form resource:
<syntaxhighlight lang="delphi">
object fmColourBar: TfmColourBar
Caption = 'fmColourBar'
OldCreateOrder = False
OnPaint = FormPaint
OnResize = FormResize
end
</syntaxhighlight>
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=TYyxCoAwDET3fsWNKqjpmMEvKZ1KhUK1UER/34uTQ7i7l0tSqyFiQ4CIQDmiHFF6pacyKzW6hz3PxoqaTyS7dHvrKMZxtR8GzHBnsXz5aHfGgwlDwQw/Qoz2nC5SvnWLewE= Run it]
<syntaxhighlight lang="text">
col[] = [ 000 900 090 009 909 099 990 999 ]
for i
rect w 100
.
</syntaxhighlight>
=={{header|Factor}}==
<
ui.gadgets ui.gadgets.tracks ui.pens.solid ;
IN: rosetta-code.colour-bars-display
Line 693 ⟶ 979:
"bars" open-window
] with-ui ;
MAIN: colors</
=={{header|Forth}}==
Line 699 ⟶ 985:
<br> The color bars are shown in Society of Motion Picture and Television Engineers (SMPTE) order.
<syntaxhighlight lang="forth">
\ Color Bars for TI-99 CAMEL99 Forth
Line 764 ⟶ 1,050:
CR .( Done. Type BARS to run)
</syntaxhighlight>
=={{header|Go}}==
{{libheader|Go Graphics}}
<
import "github.com/fogleman/gg"
Line 839 ⟶ 1,083:
drawBars(dc)
dc.SavePNG("color_bars.png")
}</
{{out}}
Line 850 ⟶ 1,094:
Terminal-based version.
<
-- stack --resolver lts-7.0 --install-ghc runghc --package vty -- -threaded
Line 870 ⟶ 1,114:
where attrs = map color2attr colors
nBars = length colors
colors = [black, brightRed, brightGreen, brightBlue, brightMagenta, brightCyan, brightYellow, brightWhite]
color2attr c = Attr Default Default (SetTo c)
main :: IO ()
main = do
cfg <- standardIOConfig
Line 887 ⟶ 1,132:
_ -> return ()
showBars bounds
shutdown vty</
[[File:Haskell_Colourbars_A_0.png|700px]]
Graphical version using SFML.
<
-- the CSFML C library. (For example, "brew install csfml" on OS X.)
Line 941 ⟶ 1,188:
withResource (createRenderWindow vMode "color bars" wStyle Nothing) $
\wnd -> withResources (mapM (makeBar $ barSize vMode) $ zip colors [0..]) $
\bars -> loop wnd bars</
=={{header|Icon}} and {{header|Unicon}}==
The procedure below is generalized to take a description of a ''test card'' and display it.
[[File:Colourbars_Simple_Unicon.png|thumb|right]]
<
procedure main() # generalized colour bars
Line 982 ⟶ 1,229:
bar(width) ] ),
band(height) ])
end</
The following example is a wee tiny bit more interesting.
[[File:Colourbars_SMPTE_Unicon.png|thumb|right]]
<
return testcard(,"SMPTE TV Test Card",width := 672,height := 504,
[ band( 1, [ bar( 1, "#c0c0c0"),
Line 1,014 ⟶ 1,261:
bar(width) ] ),
band(height) ])
end</
{{libheader|Icon Programming Library}}
Line 1,022 ⟶ 1,269:
=={{header|J}}==
<
size=: 2{.".wd'qm' NB. J6
size=: getscreenwh_jgtk_ '' NB. J7
'rgb'viewmat (|.size){. (>.&.(%&160)|.size)$ 20# 256#.255*#:i.8</
Note: You need to pick an implementation of <code>size</code> based on the version of J you are using.
=={{header|Java}}==
<
import java.awt.Color;
import java.awt.Graphics;
Line 1,059 ⟶ 1,306:
}
}
</syntaxhighlight>
=={{header|Julia}}==
{{works with|Julia|0.6}}
<
colors = [colorant"black", colorant"red", colorant"green", colorant"darkblue",
Line 1,074 ⟶ 1,321:
img[:, j:j+wcol] = col
end
save("data/colourbars.jpg", img)</
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.awt.Graphics
import javax.swing.JFrame
Line 1,102 ⟶ 1,349:
fun main(args: Array<String>) {
ColorFrame(400, 400)
}</
Editing Babbage problem
=={{header|Lua}}==
{{libheader|nw}}
{{libheader|cairo}}
<syntaxhighlight lang="lua">local nw = require("nw")
local app = nw:app()
local cw, ch = 320, 240
local win = app:window(cw, ch, "Color Bars", false)
local colors = {{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}, {1,0,1}, {0,1,1}, {1,1,0}, {1,1,1}}
local unpack = unpack or table.unpack -- polyfill 5.2 vs 5.3
function win:repaint()
local cr = win:bitmap():cairo()
for i = 1, #colors do
cr:rectangle((i-1)*cw/#colors, 0, cw/#colors, ch)
cr:rgb(unpack(colors[i]))
cr:fill()
end
end
win:show()
app:run()</syntaxhighlight>
=={{header|M2000 Interpreter}}==
Calling a module can be done by using name or call name. The later used for recursive call. Here we use it for beautify the code.
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
Module Bars {
Line 1,131 ⟶ 1,398:
}
Checkit
</syntaxhighlight>
=={{header|Maple}}==
<syntaxhighlight lang="maple">
with(plottools):
plots:-display([rectangle([0, 0], [.3, 2.1], color = black), rectangle([.3, 0], [.6, 2.1], color = red), rectangle([.6, 0], [.9, 2.1], color = green), rectangle([.9, 0], [1.2, 2.1], color = magenta), rectangle([1.2, 0], [1.5, 2.1], color = cyan), rectangle([1.5, 0], [1.8, 2.1], color = white), rectangle([1.8, 0], [2.1, 2.1], color = yellow)])
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
ConstantArray[{Black, Red, Green, Blue, Magenta, Cyan, Yellow,
White}, 5]]</
[[File:ColourBarsMathematica.png]]
=={{header|Nim}}==
{{libheader|gintro}}
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio, cairo]
const
Width = 400
Height = 300
#---------------------------------------------------------------------------------------------------
proc draw(area: DrawingArea; context: Context) =
## Draw the color bars.
const Colors = [[0.0, 0.0, 0.0], [255.0, 0.0, 0.0],
[0.0, 255.0, 0.0], [0.0, 0.0, 255.0],
[255.0, 0.0, 255.0], [0.0, 255.0, 255.0],
[255.0, 255.0, 0.0], [255.0, 255.0, 255.0]]
const
RectWidth = float(Width div Colors.len)
RectHeight = float(Height)
var x = 0.0
for color in Colors:
context.rectangle(x, 0, RectWidth, RectHeight)
context.setSource(color)
context.fill()
x += RectWidth
#---------------------------------------------------------------------------------------------------
proc onDraw(area: DrawingArea; context: Context; data: pointer): bool =
## Callback to draw/redraw the drawing area contents.
area.draw(context)
result = true
#---------------------------------------------------------------------------------------------------
proc activate(app: Application) =
## Activate the application.
let window = app.newApplicationWindow()
window.setSizeRequest(Width, Height)
window.setTitle("Color bars")
# Create the drawing area.
let area = newDrawingArea()
window.add(area)
# Connect the "draw" event to the callback to draw the spiral.
discard area.connect("draw", ondraw, pointer(nil))
window.showAll()
#———————————————————————————————————————————————————————————————————————————————————————————————————
let app = newApplication(Application, "Rosetta.ColorBars")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
=={{header|OCaml}}==
<
let round x =
Line 1,168 ⟶ 1,496:
) colors;
ignore (read_key ());
;;</
execute with:
Line 1,174 ⟶ 1,502:
=={{header|Perl}}==
<syntaxhighlight lang="perl">use strict;
use
use GD
my %colors = (
white => [255,255,255], red
magenta => [255, 0,255],
my $
my $
my $
for my $rgb ( values %colors ) {
$image->filledRectangle( $start * $barwidth , 0 , $start * $barwidth +
$barwidth - 1 , 99 , $
$start++ ;
}
open ( DISPLAY , ">" , "
binmode DISPLAY
print DISPLAY $image->png
close DISPLAY
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Colour_bars.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">colours</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">CD_BLACK</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_RED</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_GREEN</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_BLUE</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_MAGENTA</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_CYAN</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_YELLOW</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">}</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span>
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cdcanvas</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*posx*/</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">/*posy*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">height</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">lc</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">colours</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">lc</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">width</span><span style="color: #0000FF;">-</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)/(</span><span style="color: #000000;">lc</span><span style="color: #0000FF;">-</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">colours</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
<span style="color: #7060A8;">cdCanvasBox</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">+</span><span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">height</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">x</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">w</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cdcanvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupCanvas</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"RASTERSIZE=600x400"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- initial size</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`TITLE="Colour bars"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupMap</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">cdcanvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- release the minimum limitation</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
=={{header|PHP}}==
{{trans|Perl}}
Will output result directly to the browser. Use it as CGI/BIN script.
<
$colors = array(array( 0, 0, 0), // black
array(255, 0, 0), // red
Line 1,292 ⟶ 1,590:
header('Content-type:image/png');
imagepng($image);
imagedestroy($image);</
Alternately, with HTML output:
<
$colors = array(
"000000", // black
Line 1,312 ⟶ 1,610:
echo '<td style="background-color: #'.$color.'; height: 100px; width: 20px;"></td>';
}
echo '</tr></table>';</
=={{header|PicoLisp}}==
{{trans|UNIX Shell}}
<
(let Width (in '(tput cols) (read))
Line 1,325 ⟶ 1,623:
(prinl) ) )
(call 'tput 'sgr0) # reset</
=={{header|Plain English}}==
<syntaxhighlight lang="plainenglish">To run:
Start up.
Clear the screen.
Divide the screen width by 8 giving a bar width.
Make a bar with 0 and 0 and the bar width and the screen's bottom.
Draw the color bars using the bar.
Refresh the screen.
Wait for the escape key.
Shut down.
To divide the screen width by a number giving a width:
Put the screen's right into the width.
Divide the width by the number.
A bar is a box.
To draw a bar using a color and move it over:
Draw and fill the bar with the color.
Move the bar right the bar's width.
To draw the color bars using a bar:
Draw the bar using the black color and move it over.
Draw the bar using the red color and move it over.
Draw the bar using the green color and move it over.
Draw the bar using the blue color and move it over.
Draw the bar using the magenta color and move it over.
Draw the bar using the cyan color and move it over.
Draw the bar using the yellow color and move it over.
Draw and fill the bar using the white color.</syntaxhighlight>
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
[string[]]$colors = "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan",
"DarkRed" , "DarkMagenta", "DarkYellow", "Gray",
Line 1,343 ⟶ 1,672:
Write-Host
}
</syntaxhighlight>
=={{header|Processing}}==
<
noStroke();
color[] cs = {
Line 1,360 ⟶ 1,689:
fill(cs[i]);
rect(i*width/8,0,width/8,height);
}</
=={{header|Python}}==
<syntaxhighlight lang="python">
#!/usr/bin/env python
#vertical coloured stripes in window in Python 2.7.1
Line 1,383 ⟶ 1,712:
end_graphics()
</syntaxhighlight>
=={{header|R}}==
Create the color palette, set margins to zero so the image will fill the display, and use image to create the graphic:
[[File:ColorBarR.png|thumb|right]]
<syntaxhighlight lang="r">
pal <- c("black", "red", "green", "blue", "magenta", "cyan", "yellow", "white")
par(mar = rep(0, 4))
image(matrix(1:8), col = pal, axes = FALSE)
</syntaxhighlight>
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket/gui
Line 1,421 ⟶ 1,750:
(void (new full-frame%))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.10}}
<syntaxhighlight lang="raku"
my @colors = map -> $r, $g, $b { Buf.new: |(($r, $g, $b) xx $x div 8) },
Line 1,453 ⟶ 1,782:
}
$img.close;</
=={{header|REXX}}==
Line 1,464 ⟶ 1,793:
Programming note: because of the way the REXX interpreters (being used for this example) ensure screen output fidelity, if ninety characters are displayed on a ninety-byte wide screen, REXX apparently forces an extra blank, causing to what appears to be a blank line after the line displayed. Because of this, the last color bar ('''_.8''') has been shortened by one byte.
<
parse value scrsize() with sd sw . /*the screen depth and width. */
barWidth=sw%8 /*calculate the bar width. */
Line 1,489 ⟶ 1,818:
say $ /*have REXX display line of bars. */
end /*k*/ /* [↑] Note: SD could be zero. */
/*stick a fork in it, we're done. */</
This REXX program makes use of '''scrsize''' REXX program (or BIF) which is used to determine the screen size of the terminal (console).
Line 1,497 ⟶ 1,826:
=={{header|Ring}}==
<
load "guilib.ring"
Line 1,557 ⟶ 1,886:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
Output :
[https://lh3.googleusercontent.com/-_y0FSmg0NAs/V1xBPvGV2tI/AAAAAAAAAKk/TXYSJnpdZ346aQLd05yE9vLM8V9lEht1QCLcB/s1600/CalmoSoftColourBars.jpg Colour bars]
=={{header|Ruby}}==
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language
<syntaxhighlight lang="ruby">
# Array of web colors black, red, green, blue, magenta, cyan, yellow, white
PALETTE = %w[#000000 #ff0000 #00ff00 #0000ff #ff00ff #00ffff #ffffff].freeze
def settings
full_screen
end
def setup
PALETTE.each_with_index do |col, idx|
fill color(col)
rect(idx * width / 8, 0, width / 8, height)
end
end
</syntaxhighlight>
=={{header|Rust}}==
{{libheader|winit}}
{{libheader|pixels}}
renders into a borderless fullscreen window on the primary display. press ESC to close
<syntaxhighlight lang="rust">use pixels::{Pixels, SurfaceTexture}; // 0.2.0
use winit::event::*; // 0.24.0
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Fullscreen, WindowBuilder};
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Colour Bars")
.with_decorations(false)
.with_fullscreen(Some(Fullscreen::Borderless(None)))
.build(&event_loop).unwrap();
let size = window.inner_size();
let texture = SurfaceTexture::new(size.width, size.height, &window);
let mut image_buffer = Pixels::new(8, 1, texture).unwrap();
let frame = image_buffer.get_frame();
frame.copy_from_slice(&[
0x00, 0x00, 0x00, 0xFF, // black
0xFF, 0x00, 0x00, 0xFF, // red
0x00, 0xFF, 0x00, 0xFF, // green
0x00, 0x00, 0xFF, 0xFF, // blue
0xFF, 0x00, 0xFF, 0xFF, // magenta
0x00, 0xFF, 0xFF, 0xFF, // cyan
0xFF, 0xFF, 0x00, 0xFF, // yellow
0xFF, 0xFF, 0xFF, 0xFF, // white
]);
image_buffer.render().unwrap();
event_loop.run(move |ev, _, flow| {
match ev {
Event::WindowEvent {
event: WindowEvent::KeyboardInput { input, .. }, ..
} => {
if input.virtual_keycode == Some(VirtualKeyCode::Escape) {
*flow = ControlFlow::Exit;
}
}
Event::RedrawRequested(_) | Event::WindowEvent {
event: WindowEvent::Focused(true), ..
} => {
image_buffer.render().unwrap();
}
_ => {}
}
});
}</syntaxhighlight>
=={{header|Scala}}==
<
import scala.swing._
Line 1,577 ⟶ 1,978:
}
}
}</
Open window:
[[File:colorbars_scala.png|thumb|right]]
<
title="Color bars"
visible=true
preferredSize=new Dimension(640, 320)
contents=new ColorBars()
}</
=={{header|Sidef}}==
{{trans|Perl}}
<
var colors = Hash.new(
Line 1,612 ⟶ 2,013:
};
%f'colorbars.png'.open('>:raw').print(image.png);</
=={{header|Tcl}}==
{{libheader|Tk}}
<
package require Tk 8.5
Line 1,643 ⟶ 2,028:
-fill [lindex $colors 0] -outline {}
set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]
}</
==
<
clear
WIDTH=`tput cols`
Line 1,669 ⟶ 2,054:
done
tput sgr0 # reset</
=={{header|Uxntal}}==
<syntaxhighlight lang="uxntal">( uxnasm color-bars.tal color-bars.rom && uxnemu color-bars.rom )
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|0100
( set 4 color theme
rgb
color0: 000 - black
color1: f00 - red
color2: 0f0 - green
color3: 00f - blue )
#0f00 .System/r DEO2
#00f0 .System/g DEO2
#000f .System/b DEO2
( store bars width )
.Screen/width DEI2 #0004 DIV2 ,&quarter STR2
( set starting position )
#0000 .Screen/y DEO2
( draw bars )
#00
&loop
#00 OVR [ LIT2 &quarter $2 ] MUL2
.Screen/x DEO2
DUP #80 ORA .Screen/pixel DEO
INC DUP #04 NEQ ?&loop
BRK</syntaxhighlight>
[[File:Color-bars.png|alt=Color bars task implemented in Uxntal.|thumb|Color bars task implemented in Uxntal.|none]]
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "dome" for Window
class Game {
static init() {
Window.title = "Color bars"
__width = 400
__height = 400
Canvas.resize(__width, __height)
Window.resize(__width, __height)
var colors = [
Color.hex("000000"), // black
Color.hex("FF0000"), // red
Color.hex("00FF00"), // green
Color.hex("0000FF"), // blue
Color.hex("FF00FF"), // magenta
Color.hex("00FFFF"), // cyan
Color.hex("FFFF00"), // yellow
Color.hex("FFFFFF") // white
]
drawBars(colors)
}
static drawBars(colors) {
var w = __width / colors.count
var h = __height
for (i in 0...colors.count) {
Canvas.rectfill(w*i, 0, w, h, colors[i])
}
}
static update() {}
static draw(dt) {}
}</syntaxhighlight>
=={{header|XPL0}}==
<
int W, X0, X1, Y, C;
[SetVid($13); \320x200x8 graphics
Line 1,683 ⟶ 2,138:
C:= ChIn(1); \wait for keystroke
SetVid(3); \restore normal text mode
]</
{{omit from|Axe}}
{{omit from|GUISS}}
{{omit from|Minimal BASIC}}
[[Category:Test card]]
|