Software & Finance





Turbo C Graphics - Using Circle and setcolor, setbkcolor functions





I have given here the graphics source code in Turbo explaining the functions setcolor, setbkcolor, circle. setcolor is used to set the foreground color where as setbkcolor for setting the background color. The enumerated values for color are 0 -15 (BLACK - WHITE). The function circle will take 3 arguments Xcenter, Ycenter and radius and will draw the circle. The rand and randomize functions are used for animation.


Source Code


 

#include <graphics.h>

#include <math.h>

#include <conio.h>

#include <dos.h>

#include <stdlib.h>

 

 

 

void main()

{

      int i, grd, grm;

      detectgraph(&grd,&grm);

      initgraph(&grd, &grm, "");

 

 

      while(!kbhit())

      {

            randomize();

            setbkcolor(BLUE);

            setfillstyle(SOLID_FILL, BLUE);

            bar(1,1,638,478);

            setcolor(WHITE);

            rectangle(0,0,639,479);

 

            for(i = 0; i < 300; i++)

            {

                  setcolor(rand() % 10);

                  circle(rand() % 640, rand() % 480, rand() % 25);

                  delay(1);

            }

 

      }

 

      getch();

      closegraph();

}

Output