#include <iostream>
#include <graphics.h>
#include <math.h>
#include <conio.h>
using namespace std;
int width = 800;
int height = 600;
int isXiangJiao(float x1,float y1,float r1,float x2, float y2, float r2)
{
int result=0;
float l1 = pow((x1 - x2), 2) + pow((y1 - y2), 2);
float l2 = pow((r1 + r2), 2);
if (l1 < l2)
{
result = 1;
}
else
result = 0;
return result;
}
int main()
{
initgraph(width, height);
setbkcolor(WHITE);
cleardevice();
int circleNum=1;
float xArray[200];
float yArray[200];
float rArray[200];
xArray[0]= rand() % width;
yArray[0] = rand() % height;
rArray[0] = rand() % 40 + 20;
setfillcolor(YELLOW);
fillcircle(xArray[0], yArray[0], rArray[0]);
while (circleNum < 200)
{
int x = rand() % width;
int y = rand() % height;
int r = rand() % 40 + 20;
int isOk = 1;
for (int i = 0; i < circleNum; i++)
{
if (isXiangJiao(x,y,r,xArray[i], yArray[i], rArray[i]))
{
isOk = 0;
break;
}
}
if (isOk == 1)
{
xArray[circleNum] = x;
yArray[circleNum] = y;
rArray[circleNum] = r;
circleNum++;
setfillcolor(YELLOW);
fillcircle(xArray[circleNum], yArray[circleNum], rArray[circleNum]);
Sleep(30);
}
else
continue;
}
_getch();
closegraph();
}