// 变幻线.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "easyx.h"
#include "conio.h"
#include "time.h"
#define MAXPIXEL 10
void main( )
{
//初始化图形窗口
initgraph(640,480);
int y[MAXPIXEL],x[MAXPIXEL];
int i;
int m[MAXPIXEL],n[MAXPIXEL];
//随机画点、设置移动速度
for(i=0;i<MAXPIXEL;i++){
x[i]=rand()%640;
y[i]=rand()%480;
m[i]=2;
n[i]=2;
putpixel(x[i],y[i],WHITE);
}
for(i=0;i<MAXPIXEL-1;i++)//初始化连线
{
setlinecolor(WHITE);
line(x[i],y[i],x[i+1],y[i+1]);
}
//移动点
while(true)
{
BeginBatchDraw();
for(i=0;i<MAXPIXEL;i++)
{
//边界检测
if(x[i]<0 || x[i]>640)
n[i]=-n[i];
if(y[i]<0 || y[i]>480)
m[i]=-m[i];
//消除旧点,旧线
putpixel(x[i],y[i],BLACK);
setlinecolor(BLACK);
if(i<MAXPIXEL-1)
line(x[i],y[i],x[i+1],y[i+1]);
if(i!=MAXPIXEL-1)
line(x[i],y[i],x[i+1]-n[i+1],y[i+1]-m[i+1]);
y[i]=y[i]+m[i];
x[i]=x[i]+n[i];
//绘制新点
putpixel(x[i],y[i],WHITE);
//绘制连线,如果不是最后结点时相连
if(i!=MAXPIXEL-1){
setlinecolor(WHITE);
line(x[i],y[i],x[i+1],y[i+1]);
}
FlushBatchDraw();
}
EndBatchDraw();
}
//关闭图形窗口
getch();
closegraph();
}
变幻线
最新推荐文章于 2020-10-02 23:47:08 发布