/*
** Program CIRCLE_2
**
** Draws an expanding circle with sound.
** Note that the color of the circle is selected at random.
**
** Illustrates graphics, randomize, random, sound, nosound.
**
** P. H. Anderson, MSU, 10 Nov, '94
*/

#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <conio.h>
#include <time.h> /* for randomize */

void main(void)
{
	int driver, mode, n, r, color;
	driver = DETECT;  /* autotect*/
	mode = 0;
	initgraph(&driver, &mode, "c:\\turboc");
	randomize();
		/* seeds random number generator */
	while(1)
	{
	   color = random(14)+1;
	   /* note that random(n) returns a random number between
	   ** 0 and n-1.  note that color is thus a random number in the
	   ** range 1-15, thus avoiding black
	   */
	   nosound();
	   for (n=0; n<50; n++)
	   {
		 setcolor(color); /*sets the color of the circle */
		 r= (int) 200.0 * n/50;
		 circle (350, 250, r);
		 sound((int)440.0/50*n);
		 delay(20);
		 setcolor(BLACK);
		 circle (350, 250, r); /*erase the circle*/
	   }
    }
}