/* Program CIRCLE_5.C
**
** Draws up to ten circles at predefined points.
** Illustrates use of structures.
**
** P. H. Anderson, 17 Nov, 94
*/

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

struct Circle
{
   int x;
   int y;
   int r;
};  /* note global definition of the structure */

void	draw_n_circles(struct Circle *cir, int num);

void main(void)
{
	int driver, mode, n;
	struct Circle circles[10];

	/* initialize the possible circles */

	for (n=0; n<10; n++)
	{
	   circles[n].y = 250;  /* midway down the screen */
	   circles[n].r = 20;
	   circles[n].x = 70 + 700*n/10;
	}

	driver = DETECT;  /* autotect*/
	mode = 0;
	initgraph(&driver, &mode, "c:\\turboc");

	setcolor(BLUE); /*sets drawing color */

	draw_n_circles(circles, 4);  /* draw 4 circles */
	getch(); /* wait until key pressed */

	cleardevice();  /* get rid of old image */

	draw_n_circles(circles, 8); /* draw 8 circles */
	getch(); /* wait until key pressed */

	restorecrtmode(); /* restores the screen to the original screen */
}

void draw_n_circles(struct Circle *cir, int num)
{
   int n;
   setfillstyle (SOLID_FILL, YELLOW);
   for(n=0; n<num; n++)
   {
	 circle(cir[n].x, cir[n].y, cir[n].r);
	 floodfill (cir[n].x, cir[n].y, BLUE);
   }
}