如何用easyx图形库随机生成一定范围内的多个点,并用画线函数连接
关于用easyx图形库生成点
#include <stdlib.h>
#include <time.h>
#include <graphics.h>
#include <conio.h>
int main()
{
srand((unsigned)time(NULL)); // 取时间作为随机种子
initgraph(640, 480);
int x0 = rand() % 640;
int y0 = rand() % 480;
int x1, y1;
// 循环
for (int i = 0; i < 10; i++)
{
x1 = rand() % 640; // 生成随机点,自行设置范围
y1 = rand() % 480;
line(x0, y0, x1, y1);
x0 = x1;
y0 = y1;
}
_getch();
closegraph();
return 0;
}