fractus2_05.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_05.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)[2];
- int N;
- double sx,sy;
- double leng0;
- double gene_1[][2]={{0.0,1.0},{-90.0,-1.0},END};
- double gene_2[][2]={{60.0,-1.0},{-60.0,1.0},{-60.0,-1.0},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][0]);
- if((gene[i][0]+180.0)>delta||(gene[i][0]+180.0)<-delta)
- if(gene[i][1]<0)
- {warp(-gene[i][1]*leng/a);
- turn(180.0);
- fractal(-gene[i][1]*leng/a,n+1);
- turn(180.0);
- warp(-gene[i][1]*leng/a);
- }
- else fractal(gene[i][1]*leng/a,n+1);
- else warp(fabs(gene[i][1])*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)
- {
- int i=0;
- double b=0,c=0.0;
- a=0;ANGLE=0;
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- while((gene[i][0]-END)>delta||(gene[i][0]-END)<-delta)
- {turn(gene[i][0]);
- a+=fabs(gene[i][1])*cos(RADIAN);
- c+=fabs(gene[i][1])*sin(RADIAN);
- if((gene[i][0]+180.0)>delta||(gene[i][0]+180.0)<-delta)
- b+=fabs(gene[i][1]);
- i++;
- }
- n_gene=i;
- s=ANGLE;
- t=atan(c/a);a/=cos(t);
- 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][0]);
- if((gene[i][0]-180.0)>delta||(gene[i][0]-180.0)<-delta)
- move(fabs(gene[i][1])*80/a);
- else warp(fabs(gene[i][1])*80/a);
- }
- 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=16;
- sx=220.0;sy=300.0;
- leng0=200.0;
- gene=gene_1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- N=9;
- sx=170.0;sy=320.0;
- leng0=300.0;
- gene=gene_2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------