21xrx.com
2024-11-22 05:57:21 Friday
登录
文章检索 我的文章 写文章
「C语言烟花表白」:快速学习源代码 创建简单版
2023-06-17 10:54:27 深夜i     --     --
C语言 烟花表白 源代码

近几年,烟花表白已经成为绝大多数情侣们热衷的浪漫方式之一。不仅仅是情人节,各种节日或特殊的纪念日都可以用烟花表白来表达情感。很多程序员都想通过编写程序来展示自己的创意和实力。为此,我们提供了一份简单版的「C语言烟花表白」源代码,来让大家快速学习烟花表白的实现方法,掌握扩展程序的能力。

以下是我们为大家提供的源代码,包含了很多基本的语句和函数,也涉及了几个常用图形库的函数:

/*C语言烟花表白简单版*/

#include

#include

#include

#include

#include

#define N 200

#define M 800

struct z;point[N];

struct double xspeed[N];

int main()

{

  int gd=VGA,gm,i,j,k,flag=0;

  double r=3,h=13,v=3,f=20,s=4,a=1.2;

  initgraph(&gd,&gm,"");

  setcolor(0x0000FF);

  for (i=0; i

  {

    point[i].x=rand()%(M)-M/2;

    point[i].y=rand()%(400)-200;

    point[i].z=rand()%4000;

  }

  while(!kbhit())

  {

    cleardevice();

    for (i=0; i

    {

      k=0;

      for (j=0; j

      {

        if (point[i].z+f>=point[j].z

          && point[i].z-f<=point[j].z

          && point[i].x+f>=point[j].x

          && point[i].x-f<=point[j].x

          && point[i].y+f>=point[j].y

          && point[i].y-f<=point[j].y)

        {

          speed[i].x+=(point[j].x-point[i].x)/80;

          speed[i].y+=(point[j].y-point[i].y)/80;

          speed[i].z+=(point[j].z-point[i].z)/80;

          k++;

        }

      }

      speed[i].x*=0.99;

      speed[i].y*=0.99;

      speed[i].z*=0.99;

      point[i].x+=speed[i].x;

      point[i].y+=speed[i].y;

      point[i].z+=speed[i].z;

      if (k>3) continue;

      if (point[i].y<-h) point[i].y=2*h;

      if (point[i].x>2*w) point[i].x=-2*w;

      if (point[i].x<-2*w) point[i].x=2*w;

      if (point[i].z<-f) point[i].z=0.1*h-r;

      if (point[i].z>h-r) point[i].z=-0.1*h+r;

      flag=0;

      for (j=0; j

      {

        if (point[i].z>f) break;

        if (point[j].z>f) continue;

        if (point[i].z

          && point[i].x+f>=point[j].x

          && point[i].x-f<=point[j].x

          && point[i].y+f>=point[j].y

          && point[i].y-f<=point[j].y)

          flag=1;

          break;

      }

      if (flag) continue;

      if (rand()%100==0)

      {

        setcolor(rand()%1000000+0xAAAAAA);

        if (rand()%100>75)

        {

          line(2*w+h+4*point[i].z,2*h+4*point[i].y,

          2*w+h+4*point[i].z,2*h+4*point[i].y);

          line(2*w+h+4*point[i].z,2*h+4*point[i].y,

          2*w+h+4*point[i].z,2*h+4*point[i].y);

        }

        else

        {

          circle(2*w+h+4*point[i].z,2*h+4*point[i].y,

          rand()%20+1);

        }

      }

    }

    delay(16);

  }

  closegraph();

  return 0;

}

以上是一个简单的烟花表白源代码,希望大家可以借此加深对C语言图形库和算法的理解。

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复