Colour bars/Display: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: added Lua solution)
m (syntax highlighting fixup automation)
Line 19: Line 19:
=={{header|6502 Assembly}}==
=={{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.
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.
<lang 6502asm>lda #0
<syntaxhighlight lang="6502asm">lda #0
tax
tax
tay ;clear regs
tay ;clear regs
Line 68: Line 68:
jmp loop
jmp loop
exit:
exit:
brk ;on easy6502 this terminates a program. </lang>
brk ;on easy6502 this terminates a program. </syntaxhighlight>






=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>PROC Main()
<syntaxhighlight lang="action!">PROC Main()
BYTE
BYTE
i,
i,
Line 113: Line 113:
DO UNTIL CH#$FF OD
DO UNTIL CH#$FF OD
CH=$FF
CH=$FF
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Colour_bars_display.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Colour_bars_display.png Screenshot from Atari 8-bit computer]


=={{header|ActionScript}}==
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript3">
<lang ActionScript3>
package {
package {
Line 148: Line 148:
}
}
</syntaxhighlight>
</lang>


=={{header|Ada}}==
=={{header|Ada}}==
{{libheader|SDLAda}}
{{libheader|SDLAda}}
<lang Ada>with SDL.Video.Windows.Makers;
<syntaxhighlight lang="ada">with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
with SDL.Video.Palettes;
Line 200: Line 200:
Window.Finalize;
Window.Finalize;
SDL.Finalise;
SDL.Finalise;
end Colour_Bars_Display;</lang>
end Colour_Bars_Display;</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{libheader|GDI+}} (available at http://www.autohotkey.net/~tic/Gdip.ahk)
{{libheader|GDI+}} (available at http://www.autohotkey.net/~tic/Gdip.ahk)
<lang AutoHotkey>#SingleInstance, Force
<syntaxhighlight lang="autohotkey">#SingleInstance, Force
#NoEnv
#NoEnv
SetBatchLines, -1
SetBatchLines, -1
Line 296: Line 296:
Gdip_Shutdown(pToken)
Gdip_Shutdown(pToken)
ExitApp
ExitApp
Return</lang>
Return</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<lang awk>
<syntaxhighlight lang="awk">
BEGIN {
BEGIN {
nrcolors = 8
nrcolors = 8
Line 313: Line 313:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|BASIC}}==
=={{header|BASIC}}==
Line 319: Line 319:
==={{header|AmigaBASIC}}===
==={{header|AmigaBASIC}}===


<lang amigabasic>SCREEN 1,320,200,5,1
<syntaxhighlight lang="amigabasic">SCREEN 1,320,200,5,1
WINDOW 2,"Color bars",(0,10)-(297,186),15,1
WINDOW 2,"Color bars",(0,10)-(297,186),15,1
FOR a=0 TO 300
FOR a=0 TO 300
LINE (a,0)-(a,186),(a+10)/10
LINE (a,0)-(a,186),(a+10)/10
NEXT
NEXT
loop: GOTO loop</lang>
loop: GOTO loop</syntaxhighlight>


==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic>1 DATA1,12,6,3,14,13,15
<syntaxhighlight lang="applesoftbasic">1 DATA1,12,6,3,14,13,15
2 HOME : GR : FOR I = 1 TO 7
2 HOME : GR : FOR I = 1 TO 7
3 READ C(I) : NEXT
3 READ C(I) : NEXT
4 FOR I = 0 TO 39
4 FOR I = 0 TO 39
5 COLOR= C(I / 5)
5 COLOR= C(I / 5)
6 VLIN 0,39 AT I : NEXT</lang>
6 VLIN 0,39 AT I : NEXT</syntaxhighlight>


==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> SW_MAXIMIZE = 3
<syntaxhighlight lang="bbcbasic"> SW_MAXIMIZE = 3
SYS "ShowWindow", @hwnd%, SW_MAXIMIZE
SYS "ShowWindow", @hwnd%, SW_MAXIMIZE
VDU 26
VDU 26
Line 355: Line 355:
RECTANGLE FILL C%*W%, 0, W%, H%
RECTANGLE FILL C%*W%, 0, W%, H%
NEXT
NEXT
</syntaxhighlight>
</lang>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
Line 371: Line 371:
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.
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.


<lang gwbasic>5 rem color bars program
<syntaxhighlight lang="gwbasic">5 rem color bars program
10 print chr$(147);:dim co(17):c=1
10 print chr$(147);:dim co(17):c=1
20 read co(c):if co(c)>0 then c=c+1:goto 20
20 read co(c):if co(c)>0 then c=c+1:goto 20
Line 391: Line 391:
305 rem omit or rem the next line for vic-20
305 rem omit or rem the next line for vic-20
310 data 129,149,150,151,152,153,154,155
310 data 129,149,150,151,152,153,154,155
320 data 0:rem data terminato</lang>
320 data 0:rem data terminato</syntaxhighlight>


==={{header|Liberty BASIC}}===
==={{header|Liberty BASIC}}===
<lang lb>nomainwin
<syntaxhighlight lang="lb">nomainwin
colors$="black red green blue pink cyan yellow white"
colors$="black red green blue pink cyan yellow white"
WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
Line 414: Line 414:
wait
wait
[quit] close #main:end
[quit] close #main:end
</lang>
</syntaxhighlight>


==={{header|Locomotive Basic}}===
==={{header|Locomotive Basic}}===
Line 422: Line 422:
Show the default MODE 0 palette (includes two blinking colors at the end):
Show the default MODE 0 palette (includes two blinking colors at the end):


<lang locobasic>10 MODE 0:BORDER 23
<syntaxhighlight lang="locobasic">10 MODE 0:BORDER 23
20 FOR x=0 TO 15
20 FOR x=0 TO 15
30 ORIGIN x*40,0
30 ORIGIN x*40,0
40 FOR z=0 TO 39 STEP 4:MOVE z,0:DRAW z,400,x:NEXT z
40 FOR z=0 TO 39 STEP 4:MOVE z,0:DRAW z,400,x:NEXT z
50 NEXT x
50 NEXT x
60 CALL &bb06 ' wait for key press</lang>
60 CALL &bb06 ' wait for key press</syntaxhighlight>


==={{header|PureBasic}}===
==={{header|PureBasic}}===
Press Enter or Escape to exit the program.
Press Enter or Escape to exit the program.
<lang PureBasic>Dim color(7)
<syntaxhighlight lang="purebasic">Dim color(7)
color(0) = RGB($00, $00, $00) ;black
color(0) = RGB($00, $00, $00) ;black
color(1) = RGB($FF, $00, $00) ;red
color(1) = RGB($FF, $00, $00) ;red
Line 461: Line 461:
Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Return)
Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Return)
CloseScreen()
CloseScreen()
EndIf</lang>
EndIf</syntaxhighlight>
====Alternate method using console====
====Alternate method using console====
<lang PureBasic>DataSection
<syntaxhighlight lang="purebasic">DataSection
;Black, Red, Green, Blue, Magenta, Cyan, Yellow, White
;Black, Red, Green, Blue, Magenta, Cyan, Yellow, White
Data.i 0, 12, 10, 9, 13, 11, 14, 15
Data.i 0, 12, 10, 9, 13, 11, 14, 15
Line 486: Line 486:
ConsoleTitle("Press ENTER to exit"): Input()
ConsoleTitle("Press ENTER to exit"): Input()
CloseConsole()
CloseConsole()
EndIf</lang>
EndIf</syntaxhighlight>


==={{header|Run BASIC}}===
==={{header|Run BASIC}}===
<lang runbasic>colors$ = "black,red,green,blue,magenta,cyan,yellow,white"
<syntaxhighlight lang="runbasic">colors$ = "black,red,green,blue,magenta,cyan,yellow,white"
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=4><tr height=70>"
html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=4><tr height=70>"
for i = 1 to 8
for i = 1 to 8
html "<td width=20 bgcolor='";word$(colors$,i,",");"'</td>"
html "<td width=20 bgcolor='";word$(colors$,i,",");"'</td>"
next i
next i
html "</tr></table>"</lang>
html "</tr></table>"</syntaxhighlight>
<pre>Output</pre>
<pre>Output</pre>


Line 546: Line 546:


==={{header|ZX Spectrum Basic}}===
==={{header|ZX Spectrum Basic}}===
<lang zxbasic>10 REM The ZX Spectrum display is 32 columns wide, so we have 8 columns of 4 spaces
<syntaxhighlight lang="zxbasic">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
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
30 FOR c=0 TO 7: REM We use the native colour sequence here
Line 553: Line 553:
60 NEXT c
60 NEXT c
70 REM at this point the cursor has wrapped, so we don't need a newline
70 REM at this point the cursor has wrapped, so we don't need a newline
80 NEXT r</lang>
80 NEXT r</syntaxhighlight>


=={{header|Befunge}}==
=={{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.
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.
<lang befunge><v%"P": <<*"(2"
<syntaxhighlight lang="befunge"><v%"P": <<*"(2"
v_:"P"/"["39*,, :55+/68v
v_:"P"/"["39*,, :55+/68v
v,,,";1H" ,+*86%+55 ,+*<
v,,,";1H" ,+*86%+55 ,+*<
73654210v,,\,,,*93"[4m"<
73654210v,,\,,,*93"[4m"<
>$:55+%#v_:1-"P"%55+/3g^
>$:55+%#v_:1-"P"%55+/3g^
39*,,,~@>48*,1-:#v_$"m["</lang>
39*,,,~@>48*,1-:#v_$"m["</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
Line 569: Line 569:
===Text Mode===
===Text Mode===
The required functions and structures are in conio.h
The required functions and structures are in conio.h
<syntaxhighlight lang="c">
<lang C>
#include<conio.h>
#include<conio.h>


Line 602: Line 602:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


===Graphics Mode===
===Graphics Mode===
The required functions and structures are in graphics.h, conio.h is included for getch().
The required functions and structures are in graphics.h, conio.h is included for getch().
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<graphics.h>
#include<conio.h>
#include<conio.h>
Line 629: Line 629:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
Line 636: Line 636:
file <code>colorbars.h</code>:
file <code>colorbars.h</code>:


<lang cpp>#ifndef MYWIDGET_H
<syntaxhighlight lang="cpp">#ifndef MYWIDGET_H
#define MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QWidget>
Line 653: Line 653:
const int colornumber ;
const int colornumber ;
} ;
} ;
#endif</lang>
#endif</syntaxhighlight>


file <code>colorbars.cpp</code>:
file <code>colorbars.cpp</code>:


<lang cpp>#include <QtGui>
<syntaxhighlight lang="cpp">#include <QtGui>
#include "colorbars.h"
#include "colorbars.h"


Line 683: Line 683:
xstart += rectwidth + 1 ;
xstart += rectwidth + 1 ;
}
}
}</lang>
}</syntaxhighlight>


file <code>main.cpp</code>:
file <code>main.cpp</code>:


<lang cpp>#include <QApplication>
<syntaxhighlight lang="cpp">#include <QApplication>
#include "colorbars.h"
#include "colorbars.h"


Line 696: Line 696:
window.show( ) ;
window.show( ) ;
return app.exec( ) ;
return app.exec( ) ;
}</lang>
}</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. terminal-colour-bars.
PROGRAM-ID. terminal-colour-bars.


Line 751: Line 751:


GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
==={{header|ncurses}}===
==={{header|ncurses}}===
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
To interface the ncurses C library from Lisp, the ''croatoan'' library is used.
<lang lisp>(defun color-bars ()
<syntaxhighlight lang="lisp">(defun color-bars ()
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil)
(with-screen (scr :input-blocking t :input-echoing nil :cursor-visible nil)
(dotimes (i (height scr))
(dotimes (i (height scr))
Line 764: Line 764:
(refresh scr)
(refresh scr)
;; wait for keypress
;; wait for keypress
(get-char scr)))</lang>
(get-char scr)))</syntaxhighlight>
=={{header|Delphi}}==
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
{{libheader| Winapi.Windows}}
Line 771: Line 771:
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Forms}}
{{libheader| Vcl.Forms}}
<syntaxhighlight lang="delphi">
<lang Delphi>
unit Colour_barsDisplay;
unit Colour_barsDisplay;


Line 820: Line 820:
Invalidate;
Invalidate;
end;
end;
end.</lang>
end.</syntaxhighlight>
Form resource:
Form resource:
<syntaxhighlight lang="delphi">
<lang Delphi>
object fmColourBar: TfmColourBar
object fmColourBar: TfmColourBar
Caption = 'fmColourBar'
Caption = 'fmColourBar'
Line 829: Line 829:
OnResize = FormResize
OnResize = FormResize
end
end
</syntaxhighlight>
</lang>


=={{header|EasyLang}}==
=={{header|EasyLang}}==
Line 835: Line 835:
[https://easylang.online/apps/_color_bars.html Run it]
[https://easylang.online/apps/_color_bars.html Run it]


<lang>col[] = [ 000 900 090 909 099 990 999 ]
<syntaxhighlight lang="text">col[] = [ 000 900 090 909 099 990 999 ]
w = 100.0 / len col[]
w = 100.0 / len col[]
for i range len col[]
for i range len col[]
Line 841: Line 841:
move w * i 0
move w * i 0
rect w 100
rect w 100
.</lang>
.</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: accessors colors.constants kernel math sequences ui
<syntaxhighlight lang="factor">USING: accessors colors.constants kernel math sequences ui
ui.gadgets ui.gadgets.tracks ui.pens.solid ;
ui.gadgets ui.gadgets.tracks ui.pens.solid ;
IN: rosetta-code.colour-bars-display
IN: rosetta-code.colour-bars-display
Line 866: Line 866:
"bars" open-window
"bars" open-window
] with-ui ;
] with-ui ;
MAIN: colors</lang>
MAIN: colors</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
Line 872: Line 872:
<br> The color bars are shown in Society of Motion Picture and Television Engineers (SMPTE) order.
<br> The color bars are shown in Society of Motion Picture and Television Engineers (SMPTE) order.


<syntaxhighlight lang="camel99 forth">
<lang CAMEL99 Forth>
\ Color Bars for TI-99 CAMEL99 Forth
\ Color Bars for TI-99 CAMEL99 Forth


Line 940: Line 940:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<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
' Draw the color bars on an 80 x 25 console using the system palette of 16 colors
Line 958: Line 958:
' restore default settings
' restore default settings
Locate ,, 1 '' turn cursor on
Locate ,, 1 '' turn cursor on
Color 7, 0 '' white text on black background</lang>
Color 7, 0 '' white text on black background</syntaxhighlight>


=={{header|Gambas}}==
=={{header|Gambas}}==
<lang gambas>Public Sub Form_Open()
<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 iColour As Integer[] = [Color.Black, Color.red, Color.Green, Color.Magenta, Color.Cyan, Color.Yellow, Color.white]
Dim hPanel As Panel
Dim hPanel As Panel
Line 979: Line 979:
Next
Next


End</lang>
End</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
{{libheader|Go Graphics}}
{{libheader|Go Graphics}}
<lang go>package main
<syntaxhighlight lang="go">package main


import "github.com/fogleman/gg"
import "github.com/fogleman/gg"
Line 1,012: Line 1,012:
drawBars(dc)
drawBars(dc)
dc.SavePNG("color_bars.png")
dc.SavePNG("color_bars.png")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,023: Line 1,023:
Terminal-based version.
Terminal-based version.


<lang haskell>#!/usr/bin/env stack
<syntaxhighlight lang="haskell">#!/usr/bin/env stack
-- stack --resolver lts-7.0 --install-ghc runghc --package vty -- -threaded
-- stack --resolver lts-7.0 --install-ghc runghc --package vty -- -threaded


Line 1,060: Line 1,060:
_ -> return ()
_ -> return ()
showBars bounds
showBars bounds
shutdown vty</lang>
shutdown vty</syntaxhighlight>


Graphical version using SFML.
Graphical version using SFML.


<lang haskell>-- Before you can install the SFML Haskell library, you need to install
<syntaxhighlight lang="haskell">-- Before you can install the SFML Haskell library, you need to install
-- the CSFML C library. (For example, "brew install csfml" on OS X.)
-- the CSFML C library. (For example, "brew install csfml" on OS X.)


Line 1,114: Line 1,114:
withResource (createRenderWindow vMode "color bars" wStyle Nothing) $
withResource (createRenderWindow vMode "color bars" wStyle Nothing) $
\wnd -> withResources (mapM (makeBar $ barSize vMode) $ zip colors [0..]) $
\wnd -> withResources (mapM (makeBar $ barSize vMode) $ zip colors [0..]) $
\bars -> loop wnd bars</lang>
\bars -> loop wnd bars</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
The procedure below is generalized to take a description of a ''test card'' and display it.
The procedure below is generalized to take a description of a ''test card'' and display it.
[[File:Colourbars_Simple_Unicon.png|thumb|right]]
[[File:Colourbars_Simple_Unicon.png|thumb|right]]
<lang Icon>link graphics,printf
<syntaxhighlight lang="icon">link graphics,printf
procedure main() # generalized colour bars
procedure main() # generalized colour bars
Line 1,155: Line 1,155:
bar(width) ] ),
bar(width) ] ),
band(height) ])
band(height) ])
end</lang>
end</syntaxhighlight>


The following example is a wee tiny bit more interesting.
The following example is a wee tiny bit more interesting.
[[File:Colourbars_SMPTE_Unicon.png|thumb|right]]
[[File:Colourbars_SMPTE_Unicon.png|thumb|right]]
<lang Icon>procedure SMPTE_TestCard() #: return structure with 480i(ish) testcard
<syntaxhighlight lang="icon">procedure SMPTE_TestCard() #: return structure with 480i(ish) testcard
return testcard(,"SMPTE TV Test Card",width := 672,height := 504,
return testcard(,"SMPTE TV Test Card",width := 672,height := 504,
[ band( 1, [ bar( 1, "#c0c0c0"),
[ band( 1, [ bar( 1, "#c0c0c0"),
Line 1,187: Line 1,187:
bar(width) ] ),
bar(width) ] ),
band(height) ])
band(height) ])
end</lang>
end</syntaxhighlight>


{{libheader|Icon Programming Library}}
{{libheader|Icon Programming Library}}
Line 1,195: Line 1,195:
=={{header|J}}==
=={{header|J}}==


<lang j> load 'viewmat'
<syntaxhighlight lang="j"> load 'viewmat'
size=: 2{.".wd'qm' NB. J6
size=: 2{.".wd'qm' NB. J6
size=: getscreenwh_jgtk_ '' NB. J7
size=: getscreenwh_jgtk_ '' NB. J7
'rgb'viewmat (|.size){. (>.&.(%&160)|.size)$ 20# 256#.255*#:i.8</lang>
'rgb'viewmat (|.size){. (>.&.(%&160)|.size)$ 20# 256#.255*#:i.8</syntaxhighlight>


Note: You need to pick an implementation of <code>size</code> based on the version of J you are using.
Note: You need to pick an implementation of <code>size</code> based on the version of J you are using.


=={{header|Java}}==
=={{header|Java}}==
<lang java>
<syntaxhighlight lang="java">
import java.awt.Color;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics;
Line 1,232: Line 1,232:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>using Images
<syntaxhighlight lang="julia">using Images


colors = [colorant"black", colorant"red", colorant"green", colorant"darkblue",
colors = [colorant"black", colorant"red", colorant"green", colorant"darkblue",
Line 1,247: Line 1,247:
img[:, j:j+wcol] = col
img[:, j:j+wcol] = col
end
end
save("data/colourbars.jpg", img)</lang>
save("data/colourbars.jpg", img)</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Java}}
{{trans|Java}}
<lang scala>import java.awt.Color
<syntaxhighlight lang="scala">import java.awt.Color
import java.awt.Graphics
import java.awt.Graphics
import javax.swing.JFrame
import javax.swing.JFrame
Line 1,275: Line 1,275:
fun main(args: Array<String>) {
fun main(args: Array<String>) {
ColorFrame(400, 400)
ColorFrame(400, 400)
}</lang>
}</syntaxhighlight>
Editing Babbage problem
Editing Babbage problem


Line 1,281: Line 1,281:
{{libheader|nw}}
{{libheader|nw}}
{{libheader|cairo}}
{{libheader|cairo}}
<lang lua>local nw = require("nw")
<syntaxhighlight lang="lua">local nw = require("nw")
local app = nw:app()
local app = nw:app()
local cw, ch = 320, 240
local cw, ch = 320, 240
Line 1,296: Line 1,296:
end
end
win:show()
win:show()
app:run()</lang>
app:run()</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{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.
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">
<lang M2000 Interpreter>
Module Checkit {
Module Checkit {
Module Bars {
Module Bars {
Line 1,324: Line 1,324:
}
}
Checkit
Checkit
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
<syntaxhighlight lang="maple">
<lang Maple>
with(plottools):
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)])
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>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==


<lang mathematica>ArrayPlot[
<syntaxhighlight lang="mathematica">ArrayPlot[
ConstantArray[{Black, Red, Green, Blue, Magenta, Cyan, Yellow,
ConstantArray[{Black, Red, Green, Blue, Magenta, Cyan, Yellow,
White}, 5]]</lang>
White}, 5]]</syntaxhighlight>


[[File:ColourBarsMathematica.png]]
[[File:ColourBarsMathematica.png]]
Line 1,342: Line 1,342:
=={{header|Nim}}==
=={{header|Nim}}==
{{libheader|gintro}}
{{libheader|gintro}}
<lang Nim>import gintro/[glib, gobject, gtk, gio, cairo]
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio, cairo]


const
const
Line 1,399: Line 1,399:
let app = newApplication(Application, "Rosetta.ColorBars")
let app = newApplication(Application, "Rosetta.ColorBars")
discard app.connect("activate", activate)
discard app.connect("activate", activate)
discard app.run()</lang>
discard app.run()</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==


<lang ocaml>open Graphics
<syntaxhighlight lang="ocaml">open Graphics


let round x =
let round x =
Line 1,422: Line 1,422:
) colors;
) colors;
ignore (read_key ());
ignore (read_key ());
;;</lang>
;;</syntaxhighlight>


execute with:
execute with:
Line 1,428: Line 1,428:


=={{header|Perl}}==
=={{header|Perl}}==
<lang Perl>#!/usr/bin/perl -w
<syntaxhighlight lang="perl">#!/usr/bin/perl -w
use strict ;
use strict ;
use GD ;
use GD ;
Line 1,448: Line 1,448:
binmode DISPLAY ;
binmode DISPLAY ;
print DISPLAY $image->png ;
print DISPLAY $image->png ;
close DISPLAY ;#to be watched with <image viewer> testprogram.png</lang>
close DISPLAY ;#to be watched with <image viewer> testprogram.png</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
{{libheader|Phix/pGUI}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Colour_bars.exw</span>
<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;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 1,487: Line 1,487:
<span style="color: #7060A8;">IupClose</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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHP}}==
=={{header|PHP}}==
{{trans|Perl}}
{{trans|Perl}}
Will output result directly to the browser. Use it as CGI/BIN script.
Will output result directly to the browser. Use it as CGI/BIN script.
<lang PHP><?php
<syntaxhighlight lang="php"><?php
$colors = array(array( 0, 0, 0), // black
$colors = array(array( 0, 0, 0), // black
array(255, 0, 0), // red
array(255, 0, 0), // red
Line 1,516: Line 1,516:
header('Content-type:image/png');
header('Content-type:image/png');
imagepng($image);
imagepng($image);
imagedestroy($image);</lang>
imagedestroy($image);</syntaxhighlight>


Alternately, with HTML output:
Alternately, with HTML output:


<lang PHP><?php
<syntaxhighlight lang="php"><?php
$colors = array(
$colors = array(
"000000", // black
"000000", // black
Line 1,536: Line 1,536:
echo '<td style="background-color: #'.$color.'; height: 100px; width: 20px;"></td>';
echo '<td style="background-color: #'.$color.'; height: 100px; width: 20px;"></td>';
}
}
echo '</tr></table>';</lang>
echo '</tr></table>';</syntaxhighlight>


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


(let Width (in '(tput cols) (read))
(let Width (in '(tput cols) (read))
Line 1,549: Line 1,549:
(prinl) ) )
(prinl) ) )


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


=={{header|Plain English}}==
=={{header|Plain English}}==
<lang plainenglish>To run:
<syntaxhighlight lang="plainenglish">To run:
Start up.
Start up.
Clear the screen.
Clear the screen.
Line 1,580: Line 1,580:
Draw the bar using the cyan 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 the bar using the yellow color and move it over.
Draw and fill the bar using the white color.</lang>
Draw and fill the bar using the white color.</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
[string[]]$colors = "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan",
[string[]]$colors = "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan",
"DarkRed" , "DarkMagenta", "DarkYellow", "Gray",
"DarkRed" , "DarkMagenta", "DarkYellow", "Gray",
Line 1,598: Line 1,598:
Write-Host
Write-Host
}
}
</syntaxhighlight>
</lang>


=={{header|Processing}}==
=={{header|Processing}}==
<lang processing>fullScreen();
<syntaxhighlight lang="processing">fullScreen();
noStroke();
noStroke();
color[] cs = {
color[] cs = {
Line 1,615: Line 1,615:
fill(cs[i]);
fill(cs[i]);
rect(i*width/8,0,width/8,height);
rect(i*width/8,0,width/8,height);
}</lang>
}</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
#!/usr/bin/env python
#!/usr/bin/env python
#vertical coloured stripes in window in Python 2.7.1
#vertical coloured stripes in window in Python 2.7.1
Line 1,638: Line 1,638:


end_graphics()
end_graphics()
</syntaxhighlight>
</lang>


=={{header|R}}==
=={{header|R}}==
Create the color palette, set margins to zero so the image will fill the display, and use image to create the graphic:
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]]
[[File:ColorBarR.png|thumb|right]]
<syntaxhighlight lang="r">
<lang R>
pal <- c("black", "red", "green", "blue", "magenta", "cyan", "yellow", "white")
pal <- c("black", "red", "green", "blue", "magenta", "cyan", "yellow", "white")
par(mar = rep(0, 4))
par(mar = rep(0, 4))
image(matrix(1:8), col = pal, axes = FALSE)
image(matrix(1:8), col = pal, axes = FALSE)
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==


<syntaxhighlight lang="racket">
<lang Racket>
#lang racket/gui
#lang racket/gui


Line 1,676: Line 1,676:


(void (new full-frame%))
(void (new full-frame%))
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
{{works with|Rakudo|2018.10}}
{{works with|Rakudo|2018.10}}
<lang perl6>my ($x,$y) = 1280, 720;
<syntaxhighlight lang="raku" line>my ($x,$y) = 1280, 720;


my @colors = map -> $r, $g, $b { Buf.new: |(($r, $g, $b) xx $x div 8) },
my @colors = map -> $r, $g, $b { Buf.new: |(($r, $g, $b) xx $x div 8) },
Line 1,708: Line 1,708:
}
}


$img.close;</lang>
$img.close;</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,719: Line 1,719:
Programming note: &nbsp; because of the way the REXX interpreters &nbsp; (being used for this example) &nbsp; ensure screen output fidelity, &nbsp; if ninety characters are displayed on a ninety-byte wide screen, &nbsp; REXX apparently forces an extra blank, &nbsp; causing to what appears to be a blank line after the line displayed. &nbsp; Because of this, &nbsp; the last color bar &nbsp; ('''_.8''') &nbsp; has been shortened by one byte.
Programming note: &nbsp; because of the way the REXX interpreters &nbsp; (being used for this example) &nbsp; ensure screen output fidelity, &nbsp; if ninety characters are displayed on a ninety-byte wide screen, &nbsp; REXX apparently forces an extra blank, &nbsp; causing to what appears to be a blank line after the line displayed. &nbsp; Because of this, &nbsp; the last color bar &nbsp; ('''_.8''') &nbsp; has been shortened by one byte.


<lang rexx>/*REXX program displays eight colored vertical bars on a full screen. */
<syntaxhighlight lang="rexx">/*REXX program displays eight colored vertical bars on a full screen. */
parse value scrsize() with sd sw . /*the screen depth and width. */
parse value scrsize() with sd sw . /*the screen depth and width. */
barWidth=sw%8 /*calculate the bar width. */
barWidth=sw%8 /*calculate the bar width. */
Line 1,744: Line 1,744:
say $ /*have REXX display line of bars. */
say $ /*have REXX display line of bars. */
end /*k*/ /* [↑] Note: SD could be zero. */
end /*k*/ /* [↑] Note: SD could be zero. */
/*stick a fork in it, we're done. */</lang>
/*stick a fork in it, we're done. */</syntaxhighlight>
This REXX program makes use of &nbsp; '''scrsize''' &nbsp; REXX program (or BIF) which is used to determine the screen size of the terminal (console).
This REXX program makes use of &nbsp; '''scrsize''' &nbsp; REXX program (or BIF) which is used to determine the screen size of the terminal (console).


Line 1,752: Line 1,752:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
load "guilib.ring"
load "guilib.ring"


Line 1,812: Line 1,812:
}
}
label1 { setpicture(p1) show() }
label1 { setpicture(p1) show() }
</syntaxhighlight>
</lang>
Output :
Output :
[https://lh3.googleusercontent.com/-_y0FSmg0NAs/V1xBPvGV2tI/AAAAAAAAAKk/TXYSJnpdZ346aQLd05yE9vLM8V9lEht1QCLcB/s1600/CalmoSoftColourBars.jpg Colour bars]
[https://lh3.googleusercontent.com/-_y0FSmg0NAs/V1xBPvGV2tI/AAAAAAAAAKk/TXYSJnpdZ346aQLd05yE9vLM8V9lEht1QCLcB/s1600/CalmoSoftColourBars.jpg Colour bars]
Line 1,820: Line 1,820:
{{libheader|JRubyArt}}
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language
JRubyArt is a port of Processing to the ruby language
<lang ruby>
<syntaxhighlight lang="ruby">
# Array of web colors black, red, green, blue, magenta, cyan, yellow, white
# Array of web colors black, red, green, blue, magenta, cyan, yellow, white
PALETTE = %w[#000000 #ff0000 #00ff00 #0000ff #ff00ff #00ffff #ffffff].freeze
PALETTE = %w[#000000 #ff0000 #00ff00 #0000ff #ff00ff #00ffff #ffffff].freeze
Line 1,834: Line 1,834:
end
end
end
end
</syntaxhighlight>
</lang>


=={{header|Rust}}==
=={{header|Rust}}==
Line 1,840: Line 1,840:
{{libheader|pixels}}
{{libheader|pixels}}
renders into a borderless fullscreen window on the primary display. press ESC to close
renders into a borderless fullscreen window on the primary display. press ESC to close
<lang rust>use pixels::{Pixels, SurfaceTexture}; // 0.2.0
<syntaxhighlight lang="rust">use pixels::{Pixels, SurfaceTexture}; // 0.2.0
use winit::event::*; // 0.24.0
use winit::event::*; // 0.24.0
use winit::event_loop::{ControlFlow, EventLoop};
use winit::event_loop::{ControlFlow, EventLoop};
Line 1,886: Line 1,886:
}
}
});
});
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>import java.awt.Color
<syntaxhighlight lang="scala">import java.awt.Color
import scala.swing._
import scala.swing._


Line 1,904: Line 1,904:
}
}
}
}
}</lang>
}</syntaxhighlight>
Open window:
Open window:
[[File:colorbars_scala.png|thumb|right]]
[[File:colorbars_scala.png|thumb|right]]
<lang scala>new MainFrame(){
<syntaxhighlight lang="scala">new MainFrame(){
title="Color bars"
title="Color bars"
visible=true
visible=true
preferredSize=new Dimension(640, 320)
preferredSize=new Dimension(640, 320)
contents=new ColorBars()
contents=new ColorBars()
}</lang>
}</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Perl}}
{{trans|Perl}}
<lang ruby>require('GD');
<syntaxhighlight lang="ruby">require('GD');


var colors = Hash.new(
var colors = Hash.new(
Line 1,939: Line 1,939:
};
};


%f'colorbars.png'.open('>:raw').print(image.png);</lang>
%f'colorbars.png'.open('>:raw').print(image.png);</syntaxhighlight>


=={{header|SmileBASIC}}==
=={{header|SmileBASIC}}==
<lang smilebasic>FOR I=0 TO 7
<syntaxhighlight lang="smilebasic">FOR I=0 TO 7
READ R,G,B
READ R,G,B
GFILL I*50,0,I*50+49,239,RGB(R,G,B)
GFILL I*50,0,I*50+49,239,RGB(R,G,B)
Line 1,955: Line 1,955:
DATA 0,255,255
DATA 0,255,255
DATA 255,255,0
DATA 255,255,0
DATA 255,255,255</lang>
DATA 255,255,255</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{libheader|Tk}}
{{libheader|Tk}}
<lang tcl>package require Tcl 8.5
<syntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk 8.5
package require Tk 8.5


Line 1,970: Line 1,970:
-fill [lindex $colors 0] -outline {}
-fill [lindex $colors 0] -outline {}
set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]
set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]
}</lang>
}</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
<lang sh>#!/bin/sh
<syntaxhighlight lang="sh">#!/bin/sh
clear
clear
WIDTH=`tput cols`
WIDTH=`tput cols`
Line 1,996: Line 1,996:
done
done


tput sgr0 # reset</lang>
tput sgr0 # reset</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Go}}
{{trans|Go}}
{{libheader|DOME}}
{{libheader|DOME}}
<lang ecmascript>import "graphics" for Canvas, Color
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
import "dome" for Window


Line 2,035: Line 2,035:


static draw(dt) {}
static draw(dt) {}
}</lang>
}</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>include c:\cxpl\codes; \intrinsic code declarations
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \intrinsic code declarations
int W, X0, X1, Y, C;
int W, X0, X1, Y, C;
[SetVid($13); \320x200x8 graphics
[SetVid($13); \320x200x8 graphics
Line 2,049: Line 2,049:
C:= ChIn(1); \wait for keystroke
C:= ChIn(1); \wait for keystroke
SetVid(3); \restore normal text mode
SetVid(3); \restore normal text mode
]</lang>
]</syntaxhighlight>


{{omit from|Axe}}
{{omit from|Axe}}