/* Program CIRCLE_7.C
**
** Draws 3 vertical circles at predefined points.
** Illustrates use of structures.
**
** P. H. Anderson, 10 April 95
*/
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
struct Circle
{
int x;
int y;
int r;
int color;
}; /* note global definition of the structure */
void draw_3_circles(struct Circle *cir);
void fill_3_circles(struct Circle *cir);
void main(void)
{
int driver, mode, n;
struct Circle circles[3];
/* initialize the circle information */
for (n=0; n<3; n++)
{
circles[n].y = 100+n*100;
circles[n].r = 20;
circles[n].x = 100;
circles[n].color = BLACK;
}
driver = DETECT; /* autotect*/
mode = 0;
initgraph(&driver, &mode, "c:\\turboc");
setcolor(BLUE); /*sets drawing color */
while(1)
{
circles[0].color = RED;
circles[1].color = YELLOW;
circles[2].color = GREEN;
draw_3_circles(circles); /* draw the circles */
sleep(2);
cleardevice(); /* get rid of old image */
circles[0].color = BLACK;
circles[1].color = BLACK;
circles[2].color = GREEN;
draw_3_circles(circles); /* draw the circles */
sleep(2);
cleardevice(); /* get rid of old image */
circles[0].color = RED;
circles[1].color = BLACK;
circles[2].color = BLACK;
draw_3_circles(circles); /* draw the circles */
sleep(2);
cleardevice(); /* get rid of old image */
circles[0].color = BLACK;
circles[1].color = YELLOW;
circles[2].color = BLACK;
draw_3_circles(circles); /* draw the circles */
sleep(2);
}
restorecrtmode(); /* restores the screen to the original screen */
}
void draw_3_circles(struct Circle *cir)
{
int n;
for(n=0; n<3; n++)
{
setfillstyle (SOLID_FILL, cir[n].color);
circle(cir[n].x, cir[n].y, cir[n].r);
floodfill (cir[n].x, cir[n].y, BLUE);
}
}