• 当前位置:首页>>C语言>>C语言编程实例>>简单屏幕烟花程序
  • 简单屏幕烟花程序
  • 可惜一开始没能画成圆,所以整个过程都是菱形的变换,希望大家多多指教,能够想办法把初始状态就围成一个圆.

    #include "stdlib.h"
    #include"graphics.h"
    main()
    {int gd=DETECT,gr,a[8],b[8],x,y,i,j,c;
     initgraph(&gd,&gr,"");
     randomize();
     for(;!kbhit();)
     {x=rand()%500+100; /*随机中心坐标*/
      y=rand()%300+100;
      a[0]=x; /*各点坐标的计算,我的烟花图形没能是圆的*/
      b[0]=y-10;
      a[1]=a[0]+5;
      a[2]=a[1]+5;
      a[3]=a[1];
      a[4]=a[0];
      a[5]=a[0]-5;
      a[6]=a[5]-5;
      a[7]=a[6]+5;
      for(j=1;j<5;j++)
      b[j]=b[j-1]+5;
      for(j=5;j<8;j++)
      b[j]=b[j-1]-5;
      for(j=0;j<6;j++) /*烟花的大小设定*/
      {
       for(i=0;i<8;i++)
       {
       c=rand()%13+1; /*各点的颜色随机*/
       setcolor(c);
       circle(a[i],b[i],1);
       }
      delay(5000);
      cleardevice();
      b[0]-=10; /*各点的坐标变换*/
      a[1]+=5;
      b[1]-=5;
      a[2]+=10;
      a[3]+=5;
      b[3]+=5;
      b[4]+=10;
      a[5]-=5;
      b[5]+=5;
      a[6]-=10;
      a[7]-=5;
      b[7]-=5;
      }
    }
     getch();
     closegraph();
    }

     

    [1]