fractus2_10.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_10.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- int n_br;
- int n_st;
- double k,r0=180.0;
- double scale;
- double ang;
- double delta=0.0001;TRect rect;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //基本图案的反复映像生成的分形图形(2)
- void __fastcall fractal(double leng)
- {
- int i,j;double s;
- s=1;
- if(leng<=k/2||k<=1.0)
- Form1->Image1->Canvas->Pixels[LPX][LPY]=clWhite;
- else
- {for(i=0;i<n_br;i++)
- {if(!i)
- {turn(-ang/2);
- fractal(leng/k);
- turn(ang/2);
- }
- for(j=1;j<=n_st;j++,s*=scale)
- {warp(leng*s/k);
- warp(leng*s*scale/k);
- turn(ang/2);
- fractal(leng*s*scale/k);
- turn(ang/2);
- }
- turn(180.0);
- for(j=n_st;j>=1;j--,s/=scale)
- {turn(-ang);
- warp(leng*s/k);
- warp(leng*s/(scale*k));
- }
- turn(180.0);
- turn(360.0/n_br);
- }
- }
- }
- 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);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N1Click(TObject *Sender)
- {
- int i;
- double a,b;
- double s;
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- setlp(0.0,0.0);setangle(0.0);
- s=1;
- for(i=1;i<=n_st;i++,s*=scale)
- {warp(s);
- a=s*scale;
- warp(a);
- b=sqrt(LPX*LPX+LPY*LPY);
- if(k<a+b) k=a+b;
- turn(ang);
- }
- setlp(320.0,200.0);
- setangle(90.0);
- fractal(r0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_1Click(TObject *Sender)
- {
- n_br=5;n_st=3;
- scale=0.5;ang=30.0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- n_br=6;n_st=1;
- scale=0.5;ang=0.0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- n_br=6;n_st=5;
- scale=0.5;ang=0.0;
- }
- //---------------------------------------------------------------------------