Colour bars/Display: Difference between revisions

(Added COBOL solution.)
Line 121:
</lang>
 
=={{header|C}}==
This task requires functionality which allows the code to communicate to the video device. This will vary from vendor to vendor. The following examples show two ways of doing this, in the text and graphics mode, using Borland's Turbo C.
 
==={{header|Text Mode}}===
The required functions and structures are in conio.h
<lang C>
/*Abhishek Ghosh, 6th November 2013, Rotterdam*/
 
#include<conio.h>
 
#define COLOURS 8
 
int main()
{
int colour=0,i,j,MAXROW,MAXCOL;
struct text_info tInfo;
gettextinfo(&tInfo);
MAXROW = tInfo.screenheight;
MAXCOL = tInfo.screenwidth;
textbackground(BLACK); //8 colour constants are defined
clrscr();
for(colour=0;colour<COLOURS;colour++)
{
getch(); //waits for a key hit
gotoxy(1+colour*MAXCOL/COLOURS,1);
textbackground(colour);
for(j=0;j<MAXROW;j++){
for(i=0;i<MAXCOL/COLOURS;i++){
cprintf(" ");
}
gotoxy(1+colour*MAXCOL/COLOURS,1+j);
}
}
 
getch();
textbackground(BLACK);
 
return 0;
}
</lang>
 
==={{header|Graphics Mode}}===
The required functions and structures are in graphics.h, conio.h is included for getch().
<lang C>
/*Abhishek Ghosh, 6th November 2013, Rotterdam*/
#include<graphics.h>
#include<conio.h>
 
int main()
{
int d=DETECT,m,maxX,maxY,maxColours,i;
initgraph(&d,&m,"c:/turboc3/bgi");
maxX = getmaxx();
maxY = getmaxy();
maxColours = getmaxcolor();
 
for(i=0;i<maxColours;i++)
{
setfillstyle(SOLID_FILL,i);
bar(i*maxX/maxColours,0,(i+1)*maxX/maxColours,maxY);
}
 
getch();
closegraph();
return 0;
}
</lang>
=={{header|C++}}==
using Qt 4.6
503

edits