#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>
#include<math.h>
#pragma warning(disable:4966)
void drawcirle1(float x, float y, float r)
{
setlinecolor(RGB(0,25,25));
setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
fillcircle(x, y, r);
}
void drawcirle2(float x, float y, float r)
{
while (r > 0)
{
float h = rand() % 360;
COLORREF color = HSVtoRGB(h, 0.6, 0.8);
setlinecolor(RGB(255, 255, 255));
setfillcolor(color);
fillcircle(x, y, r);
r -= 3;
}
}
void drawcirle3(float x, float y, float r)
{
while (r > 0)
{
float h = rand() % 360;
COLORREF color = HSVtoRGB(h, 0.9, 0.8);
setlinecolor(color);
circle(x, y, r);
r -= 2;
}
}
float distance(float x1, float y1, float x2, float y2)
{
float result;
result = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
return result;
}
int ismeet(float x1, float y1, float r1, float x2, float y2, float r2)
{
if (distance(x1, y1, x2, y2) < r1 + r2)
return 1;//相交return 1;
return 0;
}
int random(int min, int max)
{
int r = rand() % (max - min + 1) + min;
return r;
}
void judge(float suiji,float x,float y,float r)
{
if (suiji == 1)
drawcirle1(x, y, r);
else if (suiji == 2)
drawcirle2(x, y, r);
else if (suiji == 3)
drawcirle3(x, y, r);
else if (suiji == 4)
{
suiji = rand() % 2 + 1;
judge(suiji, x, y, r);
}
}
int main()
{
int width=1000,height=700;
int number = 0;
initgraph(width,height);
setbkcolor(RGB(255, 255, 255));
cleardevice();
srand(time(0));
float suiji = rand() % 3 + 1;
int isright,i;
float x, y, r;
int x_a[5000];
int y_a[5000];
int r_a[5000];
int r_max = 50, r_min = 6;
while (number < 5000)
{
isright = 0;
while (isright == 0)
{
if (_kbhit())
{
char input = _getch();
if (input == ' ')
{
number = 0;
cleardevice();
suiji = suiji + 1;
if (suiji > 4)
suiji = 1;
}
}
x = rand() % width;
y = rand() % height;
r = r_min;
for (i = 0; i < number; i++)
{
if (ismeet(x, y, r, x_a[i], y_a[i], r_a[i]))
break;
}
if (i == number)
isright = 1;
}
isright = 0;
while (isright == 0 && r < r_max)
{
r++;
for (int j = 0; j < number; j++)
{
if (ismeet(x, y, r, x_a[j], y_a[j], r_a[j]))
{
isright = 1;
break;
}
}
}
x_a[i] = x;
y_a[i] = y;
r_a[i] = r;
number++;
judge(suiji, x, y, r);
Sleep(5);
}
_getch();
closegraph();
return 0;
}
09-26