正文

模拟烟花爆炸效果2006-07-28 10:10:00

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

分享到:

作者:liren0 下面程序在TC2.0下调式通过        小弟现丑了     请各位大哥大姐指点      付:请注意最后一个函数/******************************************    程序功能: 模似烟花爆炸较果        作者: lirne        时间: 06.04.14        联系: liren0@126.com*******************************************/#include <graphics.h>#include <math.h>#include <stdlib.h>#define SPEED 50          /*定义烟花运动的最大初速度*/#define LTIME 30          /*定义烟花的最大生命值*/#define MAX 40            /*定义烟花的最大个数*/#define g 9.8             /*定义重力加速度*//*******定义烟花结构体类型*********/struct yh{    int x0,y0;             /*烟花的爆炸的坐标*/    int x1,y1;             /*烟花某一时刻的坐标*/    int v0;                /*初速度*/    double t;    int derc;               /*运动方向*/    int ltime;               /*生命值*/    int color;               /*颜色*/};struct yhs{       int x;  /*烟花的爆炸的坐标和上面X0,Y0的值一样可去掉其一*/       int y;       int star_n;       struct yh stars[MAX];};void star_init (struct yh *,int ,int);void star_show (int,int,int,int);void star_hind (struct yh *);void star_next (struct yh *);main(){    int gd,gm;    struct yhs star;    int i;    initgraph(&gd,&gm,"");begin:    star.x=100+random(440);      /* 随机生成烟花爆炸坐标*/    star.y=100+random(280);    star.star_n=random(MAX);    for(i=0;i<star.star_n;i++)    star_init(&star.stars[i],star.x,star.y);   /*初始化烟花*/      while(!bioskey(1)){           for(i=0;i<star.star_n;i++)            star_show(star.stars[i].x1,star.stars[i].y1,                 star.stars[i].color,star.stars[i].ltime);    /*显示烟花*/            delay(10000);              /*显示延迟*/              delay(10000);            delay(10000);              delay(10000);       for(i=0;i<star.star_n;i++)           star_show(star.stars[i].x1,star.stars[i].y1,          BLACK,star.stars[i].ltime);/*隐藏烟花*/        for(i=0;i<star.star_n;i++)             star_next(&star.stars[i]);/* 计算下一步位置 */        for(i=0;i<star.star_n;i++)         if(star.stars[i].ltime>0)break;         if(i>=star.star_n)goto begin;     }     closegraph();}/****初始化烟花*******/void star_init(struct yh * sta,int x,int y){    sta->x0=sta->x1=x;    sta->y0=sta->y1=y;    sta->v0=random(SPEED);    sta->t=0;    sta->derc=random(360);    sta->ltime=random(LTIME);    sta->color=random(16);}/*******显示/隐藏烟花*******/void star_show(int x,int y,int color,int ltime){  switch(ltime/10){         /*根据生命值显示烟花大小*/     case 2:         putpixel(x,y+2,color);         putpixel(x,y-2,color);           putpixel(x+2,y,color);            putpixel(x-2,y,color);         putpixel(x,y+3,color);    case 1:         putpixel(x-1,y,color);        putpixel(x+1,y,color);         putpixel(x,y-1,color);          putpixel(x,y+1,color);           putpixel(x,y+2,color);    case 0:         putpixel(x,y,color);   }}/******计算烟花下一步的位置*******/void star_next(struct yh * sta){    sta->t+=0.1;    sta->ltime-=1;    sta->x1=sta->x0+sta->v0*cos(sta->derc/3.14)*sta->t;  /*平抛运动*/    sta->y1=sta->y0+sta->v0*(-sin(sta->derc/3.14))          *sta->t+1/2.0*g*sta->t*sta->t;       /*不知道为什么将这里的正佘弦中的弧度改为sta->derc/180*3.14 不行*/}

阅读(13884) | 评论(1)


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

评论

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