C++ 用graphics cleardevice()后在同一个窗口上连续画图的问题,急求答案啊!!!

程序是这样的,先在一个圆内,一些随机运动的点呈现2s后,消失,再出现一个十字。
# include <stdio.h>
# include <stdlib.h>
# include "graphics.h"
# include <math.h>
# include<time.h>
# include <windows.h>
# include <conio.h>

# define XMOVE 3//每次水平移动长度
# define N 150 //演示的分子数
# define DESTENCE 1500//视野距离
# define EYETHETA 6//视角
# define K (0.017453292519943295769236907684886l)//角度矫正

void main()
{
long after,before;
float deg=0,movedeg=0;
printf("请输入偏移量:\n");
scanf("%f",&movedeg);
int a=GetSystemMetrics(SM_CXSCREEN),b=GetSystemMetrics(SM_CYSCREEN);
printf("%d,%d",a,b);

initgraph(a, b);
int R = (int)(DESTENCE * (float)tan((float)(K*6)));//视野半径
int i;
int ORX = int(getmaxx()/2);//视野中心x坐标
int ORY = int(getmaxy()/2);//视野中心y坐标
int step_s = _STEP;
int theta;//极坐标角度
int len;//极坐标半径
int xnew,ynew;
int x[N],y[N]; //存放N个分子坐标
setbkcolor(0); //设置背景颜色为黑色
cleardevice(); //清屏

for(i=0;i<150;i++) //初始化N个分子位置
{
theta = (int)(rand()*R/32767.0);
len = (int)(rand()*R/32767.0);

x[i]= ORX + (int)(len * (float)cos((float)theta)); y[i]= ORY + (int)(len * (float)sin((float)theta));
putpixel(x[i],y[i],WHITE);
}
deg=deg+movedeg;
before=GetTickCount();
while(1)
{
Sleep(200);
for(i=0;i<150;i++) //某时刻分子的随机运动
{

xnew= x[i] + (int)(XMOVE*sin(K*deg));
ynew= y[i] - (int)(XMOVE*cos(K*deg));

setcolor(0);
line(x[i],y[i],xnew,ynew);
putpixel(xnew,ynew,WHITE); //在新位置显示分子
x[i]=xnew; //保存分子当前位置坐标
y[i]=ynew;
if ((x[i]-ORX) * (x[i]-ORX) + (y[i]-ORY) * (y[i]-ORY) >= R*R)
{
putpixel(xnew,ynew,BLACK);
theta = (int)(rand()*R/32767.0);
len = (int)(rand()*R/32767.0);

x[i]= ORX + (int)(len * (float)cos((float)theta)); y[i]= ORY + (int)(len * (float)sin((float)theta));
putpixel(x[i],y[i],WHITE);
}
}
after = GetTickCount();
if(after - before >= 2000) break; //时间控制
}
cleardevice();

//画十字
line((ORX-R/4),ORY,(ORX+R/4),ORY);
line(ORX,(ORY-R/4),ORX,(ORY+R/4));

system("pause");
closegraph();
printf("%d,%d",ORX,ORY);
system("pause");
}//end while

第1个回答  2012-12-27
路过顶一下哦。。。。。
相似回答
大家正在搜