/* Program BAR_3.C
**
** Illustrates how to draw a bar to represent a quantity.
**
** P. H. Anderson, 7 Dec 94
*/
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
/* #define XXX */
void draw_bar(int quan, int max_quan, int fill_color);
void main(void)
{
int graphdriver = DETECT, graphmode, linestyle=0, n;
char string[80];
initgraph(&graphdriver, &graphmode, "c:\\turboc");
/* detect and initialize graphics system */
cleardevice();
setlinestyle(SOLID_LINE, linestyle, NORM_WIDTH);
for (n=0; n<200; n++) /* make it go up */
{
draw_bar(n, 200, GREEN);
delay(100);
}
for (n=200; n>=0; n--) /* make it go down */
{
draw_bar(n, 200, GREEN);
delay(100);
}
closegraph();
}
void draw_bar(int quan, int max_quan, int fill_color)
{
int startx = 300, endx = 350, starty = 400, endy;
cleardevice();
/* draw the new bar */
endy = (400 - (int) ((float) quan / max_quan * 400));
setcolor(WHITE);
bar3d(startx, starty, endx, endy, 0, 0);
setfillstyle(SOLID_FILL, fill_color);
floodfill (325, (starty + endy) / 2, WHITE);
#ifdef XXX
/* erase any old bar */ /* problem with flicker */
setcolor(BLACK);
bar3d(startx, endy, endx, 0, 0, 0);
setfillstyle(SOLID_FILL, BLACK);
floodfill (325, endy-10, BLACK);
#endif
}