fractus2_04A.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:5k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_04A.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];
- double sx,sy;
- double leng0;
- double gene_1[][2]={{0.0,1.0},{90.0,1.0},{-90.0,1.0},{-90.0,2.0},
- {90.0,1.0},{90.0,1.0},{-90.0,1.0},END};
- double gene_2[][2]={{90.0,1.0},{-90.0,2.0},END};
- double gene_3[][2]={{0.0,1.0},{85.0,1.0},{-170.0,1.0},
- {85.0,2.0},END};
- double gene_4[][2]={{0.0,2.0},{90.0,1.0},{150.0,1.0},
- {90.0,2.0},END};
- double gene_5[][2]={{0.0,0.6},{80.0,1.0},{-180.0,1.0},{20.0,1.0},
- {-180.0,1.0},{-100.0,0.55},{80.0,0.9},{-180.0,0.9},
- {20.0,0.9},{-180.0,0.9},{-100.0,0.5},{80.0,0.8},
- {-180.0,0.8},{20.0,0.8},{-180.0,0.8},{-100.0,0.45},
- {80.0,0.7},{-180.0,0.7},{20.0,0.7},{-180.0,0.7},
- {-100.0,0.4},{80.0,0.6},{-180.0,0.6},{20.0,0.6},
- {-180.0,0.6},{-100.0,0.35},{80.0,0.5},{-180.0,0.5},
- {20.0,0.5},{-180.0,0.5},{-100.0,0.3},{80.0,0.4},
- {-180.0,0.4},{20.0,0.4},{-180.0,0.4},{-100.0,0.25},
- {80.0,0.3},{-180.0,0.3},{20.0,0.3},{-180.0,0.3},
- {-100.0,0.2},{80.0,0.2},{-180.0,0.2},{20.2,0.2},
- {-180.0,0.2},{-100.0,0.15},{80.0,0.1},{-180.0,0.1},
- {20.0,0.1},{-180.0,0.1},{-100.0,0.1},END};
- double delta=0.0001;TRect rect;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall fractal(double leng)
- {
- int i;
- if(leng<=a) 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)
- fractal(gene[i][1]*leng/a);
- else warp(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+=gene[i][1]*cos(RADIAN);
- c+=gene[i][1]*sin(RADIAN);
- if((gene[i][0]+180.0)>delta||(gene[i][0]+180.0)<-delta)
- b+=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(gene[i][1]*80/a);
- else warp(gene[i][1]*80/a);
- }
- setlp(sx,sy);
- setangle(0.0);
- fractal(leng0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_1Click(TObject *Sender)
- {
- sx=120.0;sy=200.0;
- leng0=400.0;
- gene=gene_1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- sx=220.0;sy=280.0;
- leng0=200.0;
- gene=gene_2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- sx=120.0;sy=280.0;
- leng0=400.0;
- gene=gene_3;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_4Click(TObject *Sender)
- {
- sx=120.0;sy=300.0;
- leng0=400.0;
- gene=gene_4;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_5Click(TObject *Sender)
- {
- sx=120.0;sy=200.0;
- leng0=400.0;
- gene=gene_5;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------