Hello friends welcome to Code & Coding. In this tutorial we are going to tell about Colour in Graphics C.
What is colour ?
Colour makes everything better, interesting, effective and attractive. Colour is component of lights. e.g - Red, Blue, White etc.
The colour table in Graphics C.
Colour | Int Value |
---|---|
Black | 0 |
Blue | 1 |
Green | 2 |
Cyan | 3 |
Red | 4 |
Magenta | 5 |
Brown | 6 |
Light Gray | 7 |
Dark Gray | 8 |
Light Blue | 9 |
Light Green | 10 |
Light Cyan | 11 |
Light Red | 12 |
Light Magenta | 13 |
Yellow | 14 |
White | 15 |
In Graphics in C there are various functions to set colour in shapes and background.
setcolor():
Which is used to set current colour to new colour.
setcolor(int colour value/colour name);
// Example of setcolor
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main(){
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
setcolor(RED);
//setcolor(4);
line(50,50,300,50);
getch();
}
getcolor():
//Example of getcolor
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
int gd=DETECT, gm,color;
char a[50];
initgraph(&gd,&gm,"C:\\TC\\BGI);
color=getcolor();
printf(a,”The value of the current color is %d”,color);
outtextxy(100,240,a);
getch();
}
Returns the current drawing colour.
getcolor(void);
setbkcolor():
Which is used to set background colour.
setbkcolor(int colour value/colour name);
//Example of setbkcolor()
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main(){
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
setbkcolor(GREEN);
Outtextxy(300,200,"Code&Coding");
getch();
}
getbkcolor():
Returns the background colour.
getbkcolor(void);
//Example of getbkcolor
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
int gd=DETECT, gm,bkcolor;
char a[50];
initgraph(&gd,&gm,"C:\\TC\\BGI ");
bkcolor=getbkcolor();
printf(a,”The value of the current background color is %d”,bkcolor);
outtextxy(100,240,a);
getch();
}
getmaxcolor():
Returns the maximum colour value.
getmaxcolor();
//Example of getmaxcolor
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
int gd=DETECT, gm,x=50,y=50,c;
initgraph(&gd,&gm,” “);
c=getmaxcolor();
for(i=0;i<c;i++)
{
setcolor(4);
outtextxy (x,y,"Code& Coding");
y=y+1;
}
getch();
}
0 Comments