Sample – Program to change the foreground colors and draw circles on the screen.

by Nideesh C on February 8, 2011 · 0 comments

in C++




#include <conio.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>

void main (int)
{
int gdriver=DETECT,gmode,errorcode; //Requesting auto-detection.
int midx,midy,x;
//Initializing graphics and local variables.
initgraph(&gdriver,&gmode,”d:\\bc3\\bgi”);
//Reading result of initialization.
errorcode=graphresult();
if(errorcode!=grOk)
//An error occurred.
{
printf(“Graphics error occurred : %s \n”,grapherrormsg(errorcode));
printf(“Press any key to stop : “);
getch();
exit(1); //Terminate the program due to error.
}
/*Changing the foreground color.
Note : Press enter to exit the last screen as it is black and
it may appear as if the program has stopped running.*/
for(x=15;x>=0;x–)
{
setcolor(x);
circle(20+(x*40),200,15);/*Changing x-coordinate by 50 each time so that
the circles do not overlap.*/
getch();
}
cleardevice(); //Clearing the screen in the graphics mode.
circle(200,200,50);
getch();
closegraph();
}

This graphics program changes the foreground colors on the screen gradually from white to black, in-turn drawing circles of that foreground color, using the ‘setcolor’ command.

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample – Program to change the background colors on the screen.
  2. Sample – Program to draw circles.
  3. Sample – Program to draw 2 rectangles and fill 1 of them.
  4. Sample – Program to enter an integer and print out its successor.
  5. Sample – Program to enter an integer and output the cube of that integer.

Leave a Comment

Previous post:

Next post: