大家好 小弟有下面问题想问你们 用wintc编译下面程序没有问题 但是就是不能显示效果 结果一闪就过了
怎么解决程序如下*烟花模拟程序,C语言编辑,只调用了库里画点函数,其他函数全部自行编写,tc下测试通过,运行时输入炮竹个数就行了*/#include<stdio.h>#i...
怎么解决 程序如下*烟花模拟程序,C语言编辑,只调用了库里画点函数,其他函数全部自行编写, tc下测试通过,运行时输入炮竹个数就行了*/
#include <stdio.h>
#include<math.h>
#include<conio.h>
#include <time.h>
#include<graphics.h>
#define PI 3.1415926
void Sleeptime(int s) /*延时函数*/
{
clock_t start, end;
start= clock();
do
{
end = clock();
}while(end-start<s);
return;
}
float Casteljau(int k,float *controls,float t) /*bezier曲线子函数一*/
{ int r,i;
float t1,controlsa[10];
t1=1.0-t;
for(i=0;i<=k;i++)
{controlsa[i]=controls[i];}
for(r=1;r<=k;r++)
for(i=0;i<=k-r;i++)
{controlsa[i]=t1*controlsa[i]+t*controlsa[i+1];}
return controlsa[0];
}
void bezier_to_points(int k,int npoints,float* controls,float* points)/*bezier曲线子函数二*/
{
float t,delt;
int i;
delt=1.0/npoints;
t=0.0;
for(i=0;i<=npoints;i++)
{ points[i]=Casteljau(k,controls,t);
t=t+delt;
}
}
int drawbz(int x,int y,int r) /*画图函数*/
{
int npoints=400;
int i,color=1;
float a ;
float controlsx[4];
float controlsy[4];
float points_x[401];
float points_y[401];
int k=3;
for(a=0.0;a<2*PI;a+=2*PI/180)
{
controlsx[0]=x;controlsx[1]=x+300*cos(a);
controlsx[2]=x+1200*cos(a);controlsx[3]=x+1500*cos(a);
controlsy[0]=y;controlsx[1]=y+100*sin(a);
controlsx[2]=y+300*sin(a); controlsx[3]=y+600*sin(a);
bezier_to_points(k,npoints,controlsx,points_x);
bezier_to_points(k,npoints,controlsy,points_y);
for(i=0;i<400;i++)
{
putpixel(points_x[i],points_y[i],color);
}
color++;
}
return 0;
}
int main()
{
int i,j,k,t, n;
int r,x0,y0;
int graphdriver=DETECT,graphmode;
printf("input the number of paozhu:\n");
scanf("%d",&n);
srand((unsigned)time(NULL));
/*registerbgidriver(EGAVGA_driver);*/ /*大多数编译环境,运行环境都不用这句*/
initgraph(&graphdriver,&graphmode,"");
for(i=0;i<n;i++)
{
x0=250+ rand()%140;
y0=240 + rand()%80;
r=20+rand()%20;
for(j=480;j>y0;j--)
{
for(k=10;k>0;k--)
{
putpixel(x0,j+k,RED);
putpixel(x0-1,j+k,RED);
putpixel(x0+1,j+k,RED);
}
Sleeptime(0.1);
cleardevice();
}
drawbz(x0,y0,r);
t=5+rand()%10;
Sleeptime(t);
cleardevice();
}
closegraph();
return 0;
} 展开
#include <stdio.h>
#include<math.h>
#include<conio.h>
#include <time.h>
#include<graphics.h>
#define PI 3.1415926
void Sleeptime(int s) /*延时函数*/
{
clock_t start, end;
start= clock();
do
{
end = clock();
}while(end-start<s);
return;
}
float Casteljau(int k,float *controls,float t) /*bezier曲线子函数一*/
{ int r,i;
float t1,controlsa[10];
t1=1.0-t;
for(i=0;i<=k;i++)
{controlsa[i]=controls[i];}
for(r=1;r<=k;r++)
for(i=0;i<=k-r;i++)
{controlsa[i]=t1*controlsa[i]+t*controlsa[i+1];}
return controlsa[0];
}
void bezier_to_points(int k,int npoints,float* controls,float* points)/*bezier曲线子函数二*/
{
float t,delt;
int i;
delt=1.0/npoints;
t=0.0;
for(i=0;i<=npoints;i++)
{ points[i]=Casteljau(k,controls,t);
t=t+delt;
}
}
int drawbz(int x,int y,int r) /*画图函数*/
{
int npoints=400;
int i,color=1;
float a ;
float controlsx[4];
float controlsy[4];
float points_x[401];
float points_y[401];
int k=3;
for(a=0.0;a<2*PI;a+=2*PI/180)
{
controlsx[0]=x;controlsx[1]=x+300*cos(a);
controlsx[2]=x+1200*cos(a);controlsx[3]=x+1500*cos(a);
controlsy[0]=y;controlsx[1]=y+100*sin(a);
controlsx[2]=y+300*sin(a); controlsx[3]=y+600*sin(a);
bezier_to_points(k,npoints,controlsx,points_x);
bezier_to_points(k,npoints,controlsy,points_y);
for(i=0;i<400;i++)
{
putpixel(points_x[i],points_y[i],color);
}
color++;
}
return 0;
}
int main()
{
int i,j,k,t, n;
int r,x0,y0;
int graphdriver=DETECT,graphmode;
printf("input the number of paozhu:\n");
scanf("%d",&n);
srand((unsigned)time(NULL));
/*registerbgidriver(EGAVGA_driver);*/ /*大多数编译环境,运行环境都不用这句*/
initgraph(&graphdriver,&graphmode,"");
for(i=0;i<n;i++)
{
x0=250+ rand()%140;
y0=240 + rand()%80;
r=20+rand()%20;
for(j=480;j>y0;j--)
{
for(k=10;k>0;k--)
{
putpixel(x0,j+k,RED);
putpixel(x0-1,j+k,RED);
putpixel(x0+1,j+k,RED);
}
Sleeptime(0.1);
cleardevice();
}
drawbz(x0,y0,r);
t=5+rand()%10;
Sleeptime(t);
cleardevice();
}
closegraph();
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询