**将某些点之间用线连起来,就可以做一个屏保“变幻线”的程序
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define HIGH 600
#define WIDTH 800
#define RADIUS 20
#define PN 5
typedef struct Point
{
int x;
int y;
int velocity_x;
int velocity_y;
}VPOINT;
static VPOINT vpoint[PN];
int main(void)
{
int a = 0;
initgraph(WIDTH, HIGH);
srand(time(NULL));
setbkcolor(getbkcolor());
cleardevice();
for (int i = 0; i < PN; i++)
{
vpoint[i].x = rand() % (WIDTH - RADIUS) + RADIUS;
vpoint[i].y = rand() % (HIGH - RADIUS) + RADIUS;
a = rand() % 361;
vpoint[i].velocity_x = 4 * cos(a);
vpoint[i].velocity_y = 4 * sin(a);
}
while (!_kbhit())
{
BeginBatchDraw();
cleardevice();
for (int i = 0; i < PN; i++)
{
if ((vpoint[i].x <= 0) || (vpoint[i].x >= WIDTH))
vpoint[i].velocity_x = -vpoint[i].velocity_x;
if ((vpoint[i].y <= 0) || (vpoint[i].y >= HIGH))
vpoint[i].velocity_y = -vpoint[i].velocity_y;
vpoint[i].x += vpoint[i].velocity_x;
vpoint[i].y += vpoint[i].velocity_y;
setlinecolor(BLUE);
for (int i = 0; i < PN - 1; i++)
line(vpoint[i].x, vpoint[i].y, vpoint[i + 1].x, vpoint[i + 1].y);
line(vpoint[0].x, vpoint[0].y, vpoint[PN - 1].x, vpoint[PN - 1].y);
}
EndBatchDraw();
Sleep(50);
}
closegraph();
}