正文

礼花2005-12-20 21:52:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/tankboy/8643.html

分享到:

#include "Conio.h"#include "graphics.h"#include "stdio.h"#include "stdlib.h"#include "bios.h"#include "math.h" struct cir   /*存放礼花的位置*/{   int x;   int y;}place; void initgr(void)     /* BGI初始化 */{ int gd=DETECT,gm=0;    initgraph(&gd,&gm,"");} void up()            /*礼花炮上升*/{ int aimy;  randomize();  place.x=random(440)+100;   /*设定礼花的范围*/  place.y=470;  aimy=random(300)+60;  setlinestyle(0,0,1);  setcolor(WHITE);  circle(place.x,place.y,3);  while(place.y!=aimy)       /*礼花的上升过程*/  {    setcolor(BLACK);    circle(place.x,place.y,3);    place.y--;    setcolor(WHITE);    circle(place.x,place.y,3);    delay(1000);  }       setcolor(BLACK);    circle(place.x,place.y,3);} shan()        /*礼花形状一*/  {  int j,n1,x,t1=1,y;  int p_color;  for(j=0;j<400;j++)     {       n1=rand()%2;       t1=pow(-1,n1);       x=place.x+t1*(rand()%100);       n1=rand()%2;       t1=pow(-1,n1);       y=place.y+t1*(rand()%100);      if(x<35) x=35;                     /*限制礼花越过窗体*/      if(x>getmaxx()-35) x=getmaxx()-35;      if(y<5)  y=5;       p_color=rand()%15;      setlinestyle(0,0,3);      setcolor(p_color);       line(place.x,place.y,x,y);       delay(1000);       setcolor(BLACK);                         line(place.x,place.y,x,y);     } } ceng()      /*礼花形状二*/{    float x,y,r;   int i;   int c_color;   float k;   k=2*3.14/60;   for(r=10;r<100;r++) {     for(i=0;i<60;i++)      {         x=r*sin(k*i)+place.x;         y=r*cos(k*i)+place.y;         if(x<35) x=35;                             if(x>getmaxx()-35) x=getmaxx()-35;         if(y<5)  y=5;         c_color=rand()%15;         putpixel(x,y,c_color);         delay(80);       }                }  for(r=10;r<100;r++) {     for(i=0;i<60;i++)      {         x=r*sin(k*i)+place.x;         y=r*cos(k*i)+place.y;         if(x<35) x=35;                              if(x>getmaxx()-35) x=getmaxx()-35;         if(y<5)  y=5;         putpixel(x,y,BLACK);         delay(60);       }                }} dian()      /*礼花形状三*/{  int i,j,r;  float  x[500],y[500];  float k;  int c_color;  k=2*3.14/60; for(j=0;j<500;j++)  {  i=rand()%60;  r=rand()%100;  x[j]=r*sin(k*i)+place.x;  y[j]=r*cos(k*i)+place.y;  if(x[j]<35) x[j]=35;                      if(x[j]>getmaxx()-35) x[j]=getmaxx()-35;  if(y[j]<5)  y[j]=5;  c_color=rand()%15;  setcolor(c_color);  circle(x[j],y[j],1);  delay(1500);  }  for(j=0;j<500;j++)  {  setcolor(BLACK);  circle(x[j],y[j],1);      }}void bomb()              /*礼花盛开*/{   int r1,i,n,t=1,q=1,k=1;   int pointX,pointY,point_color;   setcolor(YELLOW); /*-------------这个过程模拟礼花爆炸瞬间的状态-----------------*/   for(r1=1;r1<=4;r1++)        {      circle(place.x,place.y,r1);      delay(1000);   }   delay(3000);   setcolor(RED);   for(r1=4;r1<=6;r1++)   {      circle(place.x,place.y,r1);      delay(1000);   }   delay(3000);   setcolor(BLACK);   for(r1=6;r1>=1;r1--)   {      circle(place.x,place.y,r1);      delay(1000);   }   for(i=1;i<=20;i++)   {      point_color=rand()%15;      n=rand()%2;          t=pow(-1,n);      pointX=(t*(rand()%6)+place.x);       n=rand()%2;          t=pow(-1,n);      pointY=(t*(rand()%6)+place.y);      putpixel(pointX,pointY,point_color);      delay(2000);      putpixel(pointX,pointY,BLACK);   }/*----------------------------------------*/     n=rand()%3;     switch(n)        /*随机盛开不同的厉害*/  {   case 0:    shan(); break;   case 1:    ceng(); break;   case 2:    dian(); break;  default:     break;  }} fengmian()           /*封面程序*/{      int i,j=0;   while(1)   /**/   {      settextstyle(0,0,4);      /*设置文字输出模式*/         for(i=1;i<=15;i++)      {         setcolor(i);         outtextxy(100,180,"HAPPY NEW YEAR");  /*新年快乐*/         delay(10000);      }      j++;      if(j>5) break;   }   cleardevice();}main(){  initgr(); fengmian(); setbkcolor(BLACK);         /*绘制窗体*/ setcolor(YELLOW); setfillstyle(SOLID_FILL,9); rectangle(0,0,getmaxx(),getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); rectangle(2,2,30,getmaxy()-2); rectangle(getmaxx()-32,2,getmaxx()-2,getmaxy()-2); while(!kbhit())         /*进入礼花程序*/ {   up();   bomb(); }  getch();  closegraph(); }

阅读(2212) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册