Software & Finance





Turbo C Graphics - Using bar and setfillstyle function





I have given here the source code in Turbo C for using bar and setfillstyle function. bar takes 4 arguments left, top, right, bottom which would be same as rectangle. setfillstyle is used on how to fill the bar. It can be of 13 types 0 - 12. 0 for empty fill and 12 for user defined fill. The rest 11 values from 1 - 11 are given below:

SOLID_FILL     
LINE_FILL      
LTSLASH_FILL   
SLASH_FILL     
BKSLASH_FILL   
LTBKSLASH_FILL 
HATCH_FILL     
XHATCH_FILL    
INTERLEAVE_FILL
WIDE_DOT_FILL  
CLOSE_DOT_FILL 

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;

      int x, y, w;

      detectgraph(&grd,&grm);

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

 

 

      while(!kbhit())

      {

            randomize();

            setfillstyle(SOLID_FILL, BLUE);

            bar(1,1,638,478);

            setcolor(WHITE);

            rectangle(0,0,639,479);

 

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

            {

                  setfillstyle(rand() % 11, rand() % 15);

                  x = rand() % 639;

                  y = rand() % 479;

                  w = rand() % 25;

                  bar(x - w, y - w, x + 2, y + w);

                  delay(1);

            }

 

      }

 

      getch();

      closegraph();

}

Output