fractus2_03.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:4k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_03.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- double a=0.0,s,t;//1/a为缩小率
- int n_gene;double *gene;
- int N;
- double sx,sy;
- double leng0;
- double gene_1[]={0.0,90.0,-150.0,90.0,END};
- double gene_2[]={90.0,-90.0,END};
- double gene_3[]={0.0,90.0,-90.0,-90.0,90.0,-90.0,90.0,90.0,-90.0,END};
- double gene_4[]={0.0,120.0,-150.0,120.0,-150.0,120.0,END};
- double gene_5[]={22.5,45.0,-180.0,112.5,-45.0,-180.0,-112.5,END};
- double delta=0.0001;TRect rect;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall fractal(double leng,int n)
- {
- int i;
- if(n>=N) move(leng);
- else
- {turn(-180*t/PI);
- for(i=0;i<n_gene;i++)
- {turn(gene[i]);
- if((gene[i]+180.0)>delta||(gene[i]+180.0)<-delta)
- fractal(leng/a,n+1);
- else warp(leng/a);
- }
- turn(-s+180*t/PI);
- }
- }
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Image1->Height=0;Image1->Top=0;
- Image1->Width=Screen->Width;Image1->Height=Screen->Height;
- rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
- Image1->Canvas->CopyMode=cmBlackness;
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- Image1->Canvas->Pen->Color=clGreen;
- Image1->Canvas->Brush->Style=bsClear;
- Image1->Canvas->Font->Color=clRed;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N1Click(TObject *Sender)
- {
- char str[10];
- int b=0,i=0;
- double c=0.0,D;
- a=0;ANGLE=0;StrCopy(str,"D=");
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- while((gene[i]-END)>delta||(gene[i]-END)<-delta)
- {turn(gene[i]);
- a+=cos(RADIAN);c+=sin(RADIAN);
- if((gene[i]+180.0)>delta||(gene[i]+180.0)<-delta)
- b++;
- i++;
- }
- n_gene=i;
- s=ANGLE;
- t=atan(c/a);a/=cos(t);
- D=log10((double)b)/log10(a);
- Image1->Canvas->Rectangle(0,0,99,79);
- setlp(10.0,sy/5);
- setangle(0.0);
- turn(-180*t/PI);
- for(i=0;i<n_gene;i++)
- {turn(gene[i]);
- if((gene[i]-180.0)>delta||(gene[i]-180.0)<-delta)
- move(80/a);
- else warp(80/a);
- }
- StrPCopy(str+2,FloatToStrF(D,ffGeneral,5,1));
- Image1->Canvas->TextOut(18,90,str);
- setlp(sx,sy);
- setangle(0.0);
- fractal(leng0,0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_1Click(TObject *Sender)
- {
- N=6;
- sx=120.0;sy=240.0;
- leng0=400.0;
- gene=gene_1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- N=16;
- sx=220.0;sy=300.0;
- leng0=200.0;
- gene=gene_2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- N=4;
- sx=120.0;sy=200.0;
- leng0=400.0;
- gene=gene_3;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_4Click(TObject *Sender)
- {
- N=5;
- sx=120.0;sy=200.0;
- leng0=400.0;
- gene=gene_4;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_5Click(TObject *Sender)
- {
- N=5;
- sx=120.0;sy=200.0;
- leng0=400.0;
- gene=gene_5;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------