回 帖 发 新 帖 刷新版面

主题:[原创]雪花专辑

程序下载http://upload.programfan.com/upfile/200706241223541.rar
 专辑地址http://hucheng.programfan.com
/*01递归生成雪
花*/
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define PI 3.141592653
int main()
  {
    int gd=DETECT,gm;
    float x0=320,y0=240,r=100;
    void drawsnow(int x,int y,int r,float b);
      registerbgidriver(EGAVGA_driver);
      initgraph(&gd,&gm,"");
      drawsnow(x0,y0,r,PI/6);
      getch();
      closegraph();
      return 1;
  }
void drawsnow(int x,int y,int r,float b)
  {
        int i;
        float add,x1,y1,x2,y2;
           if (r<2) return ;
           for(add=PI/6;add<6.27;add+=PI/3)
              {
                  x1=x+r*2.0/3.0*cos(add+b);y1=y+r*2.0/3.0*sin(add+b);
                  line(x,y,x1,y1);
                  drawsnow(x1,y1,r/3.0,add+b);
              }
  }

回复列表 (共17个回复)

沙发

/*雪花02*/
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define PI 3.141592653
#define R 50
void main()
  {
     int gd=DETECT,gm;
     float b,x0,y0,x1,y1,x2,y2;
       registerbgidriver(EGAVGA_driver);
       initgraph(&gd,&gm,"");
       for(b=PI/6;b<6.27;b+=PI/3)
          {
              line(320,240,320+R*cos(b),240+R*sin(b));
              x0=320+R/4.0*cos(b);y0=240+R/4.0*sin(b);
              x1=x0+R/8.0*cos(b-PI/3);y1=y0+R/8.0*sin(b-PI/3);
              line(x0,y0,x1,y1);
              x1=x0+R/8.0*cos(b+PI/3);y1=y0+R/8.0*sin(b+PI/3);
              line(x0,y0,x1,y1);
              x0=320+R*0.5*cos(b);y0=240+R*0.5*sin(b);
            x1=x0+R/3.0*cos(b-PI/3);y1=y0+R/3.0*sin(b-PI/3); 
            x2=x0+R/8.0*cos(b-4*PI/3);y2=y0+R/8.0*sin(b-4*PI/3);
            line(x1,y1,x2,y2);
            x1=x0+R/3.0*cos(b+PI/3);y1=y0+R/3.0*sin(b+PI/3); 
            x2=x0+R/8.0*cos(b+4*PI/3);y2=y0+R/8.0*sin(b+4*PI/3);
            line(x1,y1,x2,y2);
            x0=320+R*5.0/6.0*cos(b);y0=240+R*5.0/6.0*sin(b);
            x1=x0+R/5.0*cos(b-PI/3);y1=y0+R/5.0*sin(b-PI/3);
            line(x0,y0,x1,y1);
            x1=x0+R/5.0*cos(b+PI/3);y1=y0+R/5.0*sin(b+PI/3); 
            line(x0,y0,x1,y1);     
          }  
       getch();
       closegraph();     
  }

板凳

/*雪花03*/
#include <stdio.h>
#include <math.h>
#include <graphics.h>
#include <conio.h>
#define R 50
#define PI 3.1415926
int main()
  {
    int gd=DETECT,gm;
    float x0,y0,x1,y1,b,f;
      registerbgidriver(EGAVGA_driver);
      initgraph(&gd,&gm,"");
      for(b=0;b<6.27;b+=PI/3)
         {
             x0=320+2*R*cos(b);y0=240+2*R*sin(b);
             line(320,240,x0,y0);
             x0=320+R*cos(b+PI/6);y0=240+R*sin(b+PI/6);
             x1=320+R*1.0/1.73*cos(b);y1=240+R*1.0/1.73*sin(b);
             line(x0,y0,x1,y1);
             x1=320+R*1.0/1.73*cos(b+PI/3);y1=240+R*1.0/1.73*sin(b+PI/3);
             line(x0,y0,x1,y1);
             for(f=0;f<3;f++)
                {
                     x0=320+(1+f/4.0)*R*cos(b);
                     y0=240+(1+f/4.0)*R*sin(b);
                     x1=x0+R/4.0*cos(b-PI/6);
                     y1=y0+R/4.0*sin(b-PI/6);
                     line(x0,y0,x1,y1);
                     x1=x0+R/4.0*cos(b+PI/6);
                     y1=y0+R/4.0*sin(b+PI/6);
                     line(x0,y0,x1,y1);
                }
         }      
      getch();
      closegraph();    
  }


3 楼

/*雪花04*/

#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define  PI 3.141592653
#define R 50
int main()
  {
    int gd=DETECT,gm;
    float i,b,x0,y0,x1,y1,r[]={0,0.125,0,3.0/7.0,2.5/7.0,2.0/7.0,1.0/7.0};
       registerbgidriver(EGAVGA_driver);
       initgraph(&gd,&gm,"");
       circle(320,240,2);
       for(b=PI/6;b<6.27;b+=PI/3)
          {
            line(320,240,320+R*cos(b),240+R*sin(b));
            for(i=1;i<7;i++)
               {
                  x0=320+R*i/7.0*cos(b);y0=240+R*i/7.0*sin(b);
                  x1=x0+R*r[i]*cos(b-PI/3);y1=y0+R*r[i]*sin(b-PI/3);
                  line(x0,y0,x1,y1);
                  x1=x0+R*r[i]*cos(b+PI/3);y1=y0+R*r[i]*sin(b+PI/3);
                  line(x0,y0,x1,y1);
               }
  
          }
    getch();        
    closegraph();        
                 
  }


4 楼

/*雪花05*/

#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define  PI 3.141592653
#define R 50
int main()
  {
    int gd=DETECT,gm;
    float i,b,x0,y0,x1,y1,r[]={0,.10,0,.3,.25,.20,.10};
       registerbgidriver(EGAVGA_driver);
       initgraph(&gd,&gm,"");
       circle(320,240,2);
       for(b=PI/6;b<6.27;b+=PI/3)
          {
            line(320,240,320+R*cos(b),240+R*sin(b));
            for(i=1;i<7;i++)
               {
                  x0=320+R*i/7.0*cos(b);y0=240+R*i/7.0*sin(b);
                  x1=x0+R*r[i]*cos(b-PI/4);y1=y0+R*r[i]*sin(b-PI/4);
                  line(x0,y0,x1,y1);
                  x1=x0+R*r[i]*cos(b+PI/4);y1=y0+R*r[i]*sin(b+PI/4);
                  line(x0,y0,x1,y1);
               }
            
          }
    getch();
    closegraph();        
    return 1;
  }

5 楼

/*雪花06*/
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define PI 3.141592653
#define R 50
int  main()
  {
     int gd=DETECT,gm;
     float b,x0,y0,x1,y1,x2,y2;
       registerbgidriver(EGAVGA_driver);
       initgraph(&gd,&gm,"");
       for(b=PI/6;b<6.27;b+=PI/3)
          {
              line(320,240,320+R*cos(b),240+R*sin(b));
              x0=320+R/4.0*cos(b);y0=240+R/4.0*sin(b);
              x1=x0+R/8.0*cos(b-PI/3);y1=y0+R/8.0*sin(b-PI/3);
              line(x0,y0,x1,y1);
              x1=x0+R/8.0*cos(b+PI/3);y1=y0+R/8.0*sin(b+PI/3);
              line(x0,y0,x1,y1);
              x0=320+R*3.0/8.0*cos(b);y0=240+R*3.0/8.0*sin(b);
            x1=x0+R/3.0*cos(b-PI/3);y1=y0+R/3.0*sin(b-PI/3); 
            x2=x0+R/8.0*cos(b-2*PI/3);y2=y0+R/8.0*sin(b-2*PI/3);
            line(x1,y1,x2,y2);
            x1=x0+R/3.0*cos(b+PI/3);y1=y0+R/3.0*sin(b+PI/3); 
            x2=x0+R/8.0*cos(b+2*PI/3);y2=y0+R/8.0*sin(b+2*PI/3);
            line(x1,y1,x2,y2);
            x0=320+R*5.0/6.0*cos(b);y0=240+R*5.0/6.0*sin(b);
            x1=x0+R/5.0*cos(b-PI/3);y1=y0+R/5.0*sin(b-PI/3);
            line(x0,y0,x1,y1);
            x1=x0+R/5.0*cos(b+PI/3);y1=y0+R/5.0*sin(b+PI/3); 
            line(x0,y0,x1,y1);     
          }  
     getch();
     closegraph();   
     return 1;   
  }



6 楼

/*雪花07*/
#include <stdio.h>
#include <graphics.h>
#include <bios.h>
#include <math.h>
#define PI 3.1415926
#define r 50
int main()
{
    int gd=DETECT,gm,i;
    float x,y,b;
      registerbgidriver(EGAVGA_driver);
      initgraph(&gd,&gm,"");
      for(b=1e-2;b<2*PI;b+=PI/3)
         {
          line(320,240,320+r*cos(b),240+r*sin(b));
          x=320+r/3.0*cos(b+PI/6);y=240+r/3*sin(b+PI/6);
          circle(x,y,2);
          circle(x,y,1);
          
          x=320+r/2.0*cos(b);y=240+r/2.0*sin(b);
          line(x,y,x+r/3*cos(b+PI/6),y+r/3*sin(b+PI/6));
          line(x,y,x+r/3*cos(b-PI/6),y+r/3*sin(b-PI/6));
         }
      getch();   
      closegraph();
      return 1;
}




7 楼

/*雪花07-KOCH雪花*/

#include <stdio.h>
#include <graphics.h>
#include <alloc.h>
#define R 50
typedef struct {float x,y;}dotxy;
typedef struct lnode
  {
      dotxy loc,centre;
      struct lnode *next; }lnode,*lnlink;

int main()
  {
      lnlink p,q,pr,s,newnode;
      int i,gd=DETECT,gm,x,y;
      float r,amount ,num;
        registerbgidriver(EGAVGA_driver);
        initgraph(&gd,&gm,"");
        p=(lnlink)malloc(sizeof(lnode)*3);
        if (p==NULL) exit(0);
        p[0].loc.x=320+R/2*1.73;p[0].loc.y=240-R/2;
        p[1].loc.x=320-R/2*1.73;p[1].loc.y=240-R/2;
        p[2].loc.x=320;p[2].loc.y=240+R;
      p[0].centre.x=p[1].centre.x=p[2].centre.x=320;
      p[0].centre.y=p[1].centre.y=p[2].centre.y=240;
      p[0].next=p+1;p[1].next=p+2;p[2].next=p;
      q=p,r=R,amount=3;
      while(r>1)
        { 
          num=0;
          for(i=0;i<amount;i++)
             {
               pr=q->next;            
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               s=newnode;
               newnode->next=q->next;
               q->next=s;
               s->loc.x=(2.0*q->loc.x+pr->loc.x)/3.0;
               s->loc.y=(2.0*q->loc.y+pr->loc.y)/3.0;
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               newnode->next=s->next;
               s->next=newnode;
               newnode->loc.x=q->loc.x+ pr->loc.x - q->centre.x;
               newnode->loc.y=q->loc.y+ pr->loc.y - q->centre.y;
               newnode->centre.x=(q->centre.x+2*newnode->loc.x)/3;
               newnode->centre.y=(q->centre.y+2*newnode->loc.y)/3;
               s->centre.x=newnode->centre.x;s->centre.y=newnode->centre.y;
               s=newnode;
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               newnode->next=s->next;
               s=s->next=newnode;
               s->loc.x=(q->loc.x+2*pr->loc.x)/3;
               s->loc.y=(q->loc.y+2*pr->loc.y)/3;
               s->centre.x=(q->centre.x+2*pr->loc.x)/3;
               s->centre.y=(q->centre.y+2*pr->loc.y)/3;
               q->centre.x=(q->centre.x+2*q->loc.x)/3;
               q->centre.y=(q->centre.y+2*q->loc.y)/3;
               q=pr;
               num+=3;
             }    
          r/=3.0;amount+=num;   
        }
     for(i=0,q=p;i<amount;i++,q=q->next)
        {
          line(q->loc.x,q->loc.y,q->next->loc.x,q->next->loc.y);
          
        }
    for(i=0,q=p;i<amount-1;i++)
        {
          s=q,q=q->next;
          free(s);     
        }   
     getch();
     closegraph();   
     return 1; 
  }

8 楼

如遇到这样的错误:
fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory
请问怎解决?

9 楼

#include <stdio.h>
/*KOCH雪花2*/
#include <graphics.h>
#include <math.h>
#include <alloc.h>
#define R 50
#define PI 3.1416926
typedef struct {float x,y;}dotxy;
typedef struct lnode
  {
      dotxy loc,centre;
      struct lnode *next; }lnode,*lnlink;

int main()
  {
      lnlink p,q,pr,s,newnode;
      int i,gd=DETECT,gm;
      float r,amount ,num,x0,y0,x1,y1,b;
        registerbgidriver(EGAVGA_driver);
        initgraph(&gd,&gm,"");
        p=(lnlink)malloc(sizeof(lnode)*3);
        if (p==NULL) exit(0);
        p[0].loc.x=320+R/2*1.73;p[0].loc.y=240-R/2;
        p[1].loc.x=320-R/2*1.73;p[1].loc.y=240-R/2;
        p[2].loc.x=320;p[2].loc.y=240+R;
      p[0].centre.x=p[1].centre.x=p[2].centre.x=320;
      p[0].centre.y=p[1].centre.y=p[2].centre.y=240;
      p[0].next=p+1;p[1].next=p+2;p[2].next=p;
      q=p,r=R,amount=3;
      while(r>1)
        { 
          num=0;
          for(i=0;i<amount;i++)
             {
               pr=q->next;            
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               s=newnode;
               newnode->next=q->next;
               q->next=s;
               s->loc.x=(2.0*q->loc.x+pr->loc.x)/3.0;
               s->loc.y=(2.0*q->loc.y+pr->loc.y)/3.0;
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               newnode->next=s->next;
               s->next=newnode;
               newnode->loc.x=q->loc.x+ pr->loc.x - q->centre.x;
               newnode->loc.y=q->loc.y+ pr->loc.y - q->centre.y;
               newnode->centre.x=(q->centre.x+2*newnode->loc.x)/3;
               newnode->centre.y=(q->centre.y+2*newnode->loc.y)/3;
               s->centre.x=newnode->centre.x;s->centre.y=newnode->centre.y;
               s=newnode;
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               newnode->next=s->next;
               s=s->next=newnode;
               s->loc.x=(q->loc.x+2*pr->loc.x)/3;
               s->loc.y=(q->loc.y+2*pr->loc.y)/3;
               s->centre.x=(q->centre.x+2*pr->loc.x)/3;
               s->centre.y=(q->centre.y+2*pr->loc.y)/3;
               q->centre.x=(q->centre.x+2*q->loc.x)/3;
               q->centre.y=(q->centre.y+2*q->loc.y)/3;
               q=pr;
               num+=3;
             }    
          r/=3.0;amount+=num;   
        }
     for(i=0,q=p;i<amount;i++,q=q->next)
        {
          line(q->loc.x,q->loc.y,q->next->loc.x,q->next->loc.y);
        }
     s=p,q=p->next;
     while(q!=p){free(s);s=q;q=q->next;}   
     for(b=0;b<6.27;b+=PI/3)
        {
              x1=320+R*2*cos(b);y1=240+R*2*sin(b);
              line(320,240,x1,y1);
              for(i=0;i<3;i++)
                 {
                    x0=320+(1+i/3.0)*R*cos(b);y0=240+(1+i/3.0)*R*sin(b);
                    x1=x0+R/5*cos(b+PI/6);y1=y0+R/5*sin(b+PI/6);
                    line(x0,y0,x1,y1);
                    x1=x0+R/5*cos(b-PI/6);y1=y0+R/5*sin(b-PI/6);
                   
                     line(x0,y0,x1,y1);
                 }
        }   
     getch();
     closegraph();   
     return 1; 
  }

10 楼

/*KOCH雪花3*/
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <alloc.h>
#define R 50
#define PI 3.1416926
typedef struct {float x,y;}dotxy;
typedef struct lnode
  {
      dotxy loc,centre;
      struct lnode *next; }lnode,*lnlink;

int main()
  {
      lnlink p,q,pr,s,newnode;
      int i,gd=DETECT,gm;
      float r,amount ,num,x0,y0,x1,y1,b;
        registerbgidriver(EGAVGA_driver);
        initgraph(&gd,&gm,"");
        p=(lnlink)malloc(sizeof(lnode)*3);
        if (p==NULL) exit(0);
        p[0].loc.x=320+R/2*1.73;p[0].loc.y=240-R/2;
        p[1].loc.x=320-R/2*1.73;p[1].loc.y=240-R/2;
        p[2].loc.x=320;p[2].loc.y=240+R;
      p[0].centre.x=p[1].centre.x=p[2].centre.x=320;
      p[0].centre.y=p[1].centre.y=p[2].centre.y=240;
      p[0].next=p+1;p[1].next=p+2;p[2].next=p;
      q=p,r=R,amount=3;
      while(r>1)
        { 
          num=0;
          for(i=0;i<amount;i++)
             {
               pr=q->next;            
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               s=newnode;
               newnode->next=q->next;
               q->next=s;
               s->loc.x=(2.0*q->loc.x+pr->loc.x)/3.0;
               s->loc.y=(2.0*q->loc.y+pr->loc.y)/3.0;
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               newnode->next=s->next;
               s->next=newnode;
               newnode->loc.x=q->loc.x+ pr->loc.x - q->centre.x;
               newnode->loc.y=q->loc.y+ pr->loc.y - q->centre.y;
               newnode->centre.x=(q->centre.x+2*newnode->loc.x)/3;
               newnode->centre.y=(q->centre.y+2*newnode->loc.y)/3;
               s->centre.x=newnode->centre.x;s->centre.y=newnode->centre.y;
               s=newnode;
               newnode=(lnlink)malloc(sizeof(lnode));
               if (newnode==NULL) exit(0);
               newnode->next=s->next;
               s=s->next=newnode;
               s->loc.x=(q->loc.x+2*pr->loc.x)/3;
               s->loc.y=(q->loc.y+2*pr->loc.y)/3;
               s->centre.x=(q->centre.x+2*pr->loc.x)/3;
               s->centre.y=(q->centre.y+2*pr->loc.y)/3;
               q->centre.x=(q->centre.x+2*q->loc.x)/3;
               q->centre.y=(q->centre.y+2*q->loc.y)/3;
               q=pr;
               num+=3;
             }    
          r/=3.0;amount+=num;   
        }
     for(i=0,q=p;i<amount;i++,q=q->next)
        {
          line(q->loc.x,q->loc.y,q->next->loc.x,q->next->loc.y);
        }
     s=p,q=p->next;
     while(q!=p){free(s);s=q;q=q->next;}   
     for(b=0;b<6.27;b+=PI/3)
        {
              x1=320+R*2*cos(b);y1=240+R*2*sin(b);
              line(320,240,x1,y1);
              for(i=0;i<3;i++)
                 {
                    x0=320+(1+i/3.0)*R*cos(b);y0=240+(1+i/3.0)*R*sin(b);
                    x1=x0+R/5*cos(b+PI/6);y1=y0+R/5*sin(b+PI/6);
                    line(x0,y0,x1,y1);
                    x1=x0+R/5*cos(b-PI/6);y1=y0+R/5*sin(b-PI/6);
                   
                     line(x0,y0,x1,y1);
                 }
        }   
     getch();
     closegraph();   
     return 1; 
  }

我来回复

您尚未登录,请登录后再回复。点此登录或注册