11111待

#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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值