首页 > 学院 > 开发设计 > 正文

一个简单的焰火程序

2019-11-17 05:30:50
字体:
来源:转载
供稿:网友
#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#define PI 3.14159
#define maxx 640
#define maxy 480main()
{int i;
 char c;
 init();
 draw();
 c=getch();
}
init()
/*初始化图形系统函数*/
{int gdriver=DETECT,gmode;
 initgraph(&gdriver,&gmode,"c://tc//bgi"); /*注重此处的路径*/
 setbkcolor(1);
 sky();
 return;
}sky()
{int x,y,i;
 for(i=1;i<=500;i++)
  {x=rand()%640;y=rand()%300;
   putpixel(x,y,15);
   putpixel(x+1,y,15);
  }
 for(i=1;i<=200;i++)
  {x=rand()%640;y=300+rand()%100;
   putpixel(x,y,15);
  }
return;
}
draw()
{int i,j,k,x,y,dy;
 setfillstyle(1,7);
for(i=1;i<=10;i++)
 {setlinestyle(3,0,3);
  x=100+rand()%400;dy=20+rand()%20;
  for(k=1000;k>=500;k-=100)
   {sound(k);delay(3000);}
  nosound();
  for(j=1;j<=10;j++)
   {setcolor(i%16);
    line(x,maxy-(j-1)*dy,x,maxy-j*dy);
    delay(10000);
    setcolor(0);
    line(x,maxy-(j-1)*dy,x,maxy-j*dy);
   }
  for(k=6000;k>=3000;k-=100)
    {sound(k);delay(20000);}
  nosound();
  setlinestyle(3,0,2);
  drawellipse(x,maxy-(j-1)*dy);
 }return;
}
drawellipse(int x,int y)
{int i,j,x1,y1,a,b;
 float q;
 a=60+rand()%60;b=a-rand()%60;
 for(i=2;i>=0;i--)
 {
 for(q=0;q<=2*PI;q+=0.12)
  {setcolor(rand()%16);
   x1=x+(a-i*30)*cos(q);
   y1=y-(b-i*30)*sin(q);
   line(x,y,x1,y1);
  }
 delay(50000);
 setcolor(0);
  for(q=0;q<=2*PI;q+=0.12)
  {x1=x+(a-i*30)*cos(q);
   y1=y-(b-i*30)*sin(q);
   line(x,y,x1,y1);
  } }
 return;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表