fractus2_10_b.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_10_b.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- int n_br=4;
- int n_st=8;
- double k,r0=180.0;
- double scale=0.6;
- double ang=25.0;
- double delta=0.0001;TRect rect;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //分形状宇宙
- void __fastcall fractal(double leng,double angle)
- {
- 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(-angle/2);
- fractal(leng/k,angle);
- turn(angle/2);
- }
- for(j=1;j<=n_st;j++,s*=scale)
- {warp(leng*s/k);
- warp(leng*s*scale/k);
- turn(angle/2);
- fractal(leng*s*scale/k,angle/2);
- turn(angle/2);
- }
- turn(180.0);
- for(j=n_st;j>=1;j--,s/=scale)
- {turn(-angle);
- 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,ang);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------