Colour bars/Display: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|Lua}}: added Lua solution) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19:
=={{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.
<
tax
tay ;clear regs
Line 68:
jmp loop
exit:
brk ;on easy6502 this terminates a program. </
=={{header|Action!}}==
<
BYTE
i,
Line 113:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{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 148:
}
</syntaxhighlight>
=={{header|Ada}}==
{{libheader|SDLAda}}
<
with SDL.Video.Renderers.Makers;
with SDL.Video.Palettes;
Line 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 296:
Gdip_Shutdown(pToken)
ExitApp
Return</
=={{header|AWK}}==
<
BEGIN {
nrcolors = 8
Line 313:
}
}
</syntaxhighlight>
=={{header|BASIC}}==
Line 319:
==={{header|AmigaBASIC}}===
<
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</
==={{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 355:
RECTANGLE FILL C%*W%, 0, W%, H%
NEXT
</syntaxhighlight>
==={{header|Commodore BASIC}}===
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.
<
10 print chr$(147);:dim co(17):c=1
20 read co(c):if co(c)>0 then c=c+1:goto 20
Line 391:
305 rem omit or rem the next line for vic-20
310 data 129,149,150,151,152,153,154,155
320 data 0:rem data terminato</
==={{header|Liberty BASIC}}===
<
colors$="black red green blue pink cyan yellow white"
WindowWidth=DisplayWidth:WindowHeight=DisplayHeight
Line 414:
wait
[quit] close #main:end
</
==={{header|Locomotive Basic}}===
Line 422:
Show the default MODE 0 palette (includes two blinking colors at the end):
<
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</
==={{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 461:
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 486:
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>
Line 546:
==={{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 553:
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 569:
===Text Mode===
The required functions and structures are in conio.h
<syntaxhighlight lang="c">
#include<conio.h>
Line 602:
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 629:
return 0;
}
</syntaxhighlight>
=={{header|C++}}==
Line 636:
file <code>colorbars.h</code>:
<
#define MYWIDGET_H
#include <QWidget>
Line 653:
const int colornumber ;
} ;
#endif</
file <code>colorbars.cpp</code>:
<
#include "colorbars.h"
Line 683:
xstart += rectwidth + 1 ;
}
}</
file <code>main.cpp</code>:
<
#include "colorbars.h"
Line 696:
window.show( ) ;
return app.exec( ) ;
}</
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
PROGRAM-ID. terminal-colour-bars.
Line 751:
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 764:
(refresh scr)
;; wait for keypress
(get-char scr)))</
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 771:
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Forms}}
<syntaxhighlight lang="delphi">
unit Colour_barsDisplay;
Line 820:
Invalidate;
end;
end.</
Form resource:
<syntaxhighlight lang="delphi">
object fmColourBar: TfmColourBar
Caption = 'fmColourBar'
Line 829:
OnResize = FormResize
end
</syntaxhighlight>
=={{header|EasyLang}}==
Line 835:
[https://easylang.online/apps/_color_bars.html Run it]
<syntaxhighlight lang="text">col[] = [ 000 900 090 909 099 990 999 ]
w = 100.0 / len col[]
for i range len col[]
Line 841:
move w * i 0
rect w 100
.</
=={{header|Factor}}==
<
ui.gadgets ui.gadgets.tracks ui.pens.solid ;
IN: rosetta-code.colour-bars-display
Line 866:
"bars" open-window
] with-ui ;
MAIN: colors</
=={{header|Forth}}==
Line 872:
<br> The color bars are shown in Society of Motion Picture and Television Engineers (SMPTE) order.
<syntaxhighlight lang="camel99 forth">
\ Color Bars for TI-99 CAMEL99 Forth
Line 940:
=={{header|FreeBASIC}}==
<
' Draw the color bars on an 80 x 25 console using the system palette of 16 colors
Line 958:
' restore default settings
Locate ,, 1 '' turn cursor on
Color 7, 0 '' white text on black background</
=={{header|Gambas}}==
<
Dim iColour As Integer[] = [Color.Black, Color.red, Color.Green, Color.Magenta, Color.Cyan, Color.Yellow, Color.white]
Dim hPanel As Panel
Line 979:
Next
End</
=={{header|Go}}==
{{libheader|Go Graphics}}
<
import "github.com/fogleman/gg"
Line 1,012:
drawBars(dc)
dc.SavePNG("color_bars.png")
}</
{{out}}
Line 1,023:
Terminal-based version.
<
-- stack --resolver lts-7.0 --install-ghc runghc --package vty -- -threaded
Line 1,060:
_ -> return ()
showBars bounds
shutdown vty</
Graphical version using SFML.
<
-- the CSFML C library. (For example, "brew install csfml" on OS X.)
Line 1,114:
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 1,155:
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,187:
bar(width) ] ),
band(height) ])
end</
{{libheader|Icon Programming Library}}
Line 1,195:
=={{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,232:
}
}
</syntaxhighlight>
=={{header|Julia}}==
{{works with|Julia|0.6}}
<
colors = [colorant"black", colorant"red", colorant"green", colorant"darkblue",
Line 1,247:
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,275:
fun main(args: Array<String>) {
ColorFrame(400, 400)
}</
Editing Babbage problem
Line 1,281:
{{libheader|nw}}
{{libheader|cairo}}
<
local app = nw:app()
local cw, ch = 320, 240
Line 1,296:
end
win:show()
app:run()</
=={{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,324:
}
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]]
Line 1,342:
=={{header|Nim}}==
{{libheader|gintro}}
<
const
Line 1,399:
let app = newApplication(Application, "Rosetta.ColorBars")
discard app.connect("activate", activate)
discard app.run()</
=={{header|OCaml}}==
<
let round x =
Line 1,422:
) colors;
ignore (read_key ());
;;</
execute with:
Line 1,428:
=={{header|Perl}}==
<
use strict ;
use GD ;
Line 1,448:
binmode DISPLAY ;
print DISPLAY $image->png ;
close DISPLAY ;#to be watched with <image viewer> testprogram.png</
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
<!--<
<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>
Line 1,487:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{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,516:
header('Content-type:image/png');
imagepng($image);
imagedestroy($image);</
Alternately, with HTML output:
<
$colors = array(
"000000", // black
Line 1,536:
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,549:
(prinl) ) )
(call 'tput 'sgr0) # reset</
=={{header|Plain English}}==
<
Start up.
Clear the screen.
Line 1,580:
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.</
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
[string[]]$colors = "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan",
"DarkRed" , "DarkMagenta", "DarkYellow", "Gray",
Line 1,598:
Write-Host
}
</syntaxhighlight>
=={{header|Processing}}==
<
noStroke();
color[] cs = {
Line 1,615:
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,638:
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,676:
(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,708:
}
$img.close;</
=={{header|REXX}}==
Line 1,719:
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,744:
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,752:
=={{header|Ring}}==
<
load "guilib.ring"
Line 1,812:
}
label1 { setpicture(p1) show() }
</syntaxhighlight>
Output :
[https://lh3.googleusercontent.com/-_y0FSmg0NAs/V1xBPvGV2tI/AAAAAAAAAKk/TXYSJnpdZ346aQLd05yE9vLM8V9lEht1QCLcB/s1600/CalmoSoftColourBars.jpg Colour bars]
Line 1,820:
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language
<
# Array of web colors black, red, green, blue, magenta, cyan, yellow, white
PALETTE = %w[#000000 #ff0000 #00ff00 #0000ff #ff00ff #00ffff #ffffff].freeze
Line 1,834:
end
end
</syntaxhighlight>
=={{header|Rust}}==
Line 1,840:
{{libheader|pixels}}
renders into a borderless fullscreen window on the primary display. press ESC to close
<
use winit::event::*; // 0.24.0
use winit::event_loop::{ControlFlow, EventLoop};
Line 1,886:
}
});
}</
=={{header|Scala}}==
<
import scala.swing._
Line 1,904:
}
}
}</
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,939:
};
%f'colorbars.png'.open('>:raw').print(image.png);</
=={{header|SmileBASIC}}==
<
READ R,G,B
GFILL I*50,0,I*50+49,239,RGB(R,G,B)
Line 1,955:
DATA 0,255,255
DATA 255,255,0
DATA 255,255,255</
=={{header|Tcl}}==
{{libheader|Tk}}
<
package require Tk 8.5
Line 1,970:
-fill [lindex $colors 0] -outline {}
set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]
}</
=={{header|UNIX Shell}}==
<
clear
WIDTH=`tput cols`
Line 1,996:
done
tput sgr0 # reset</
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<
import "dome" for Window
Line 2,035:
static draw(dt) {}
}</
=={{header|XPL0}}==
<
int W, X0, X1, Y, C;
[SetVid($13); \320x200x8 graphics
Line 2,049:
C:= ChIn(1); \wait for keystroke
SetVid(3); \restore normal text mode
]</
{{omit from|Axe}}
|