fractus2_08.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:2k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_08.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- int N=12;
- double a,b,t=0.57735;
- double sx=120.0,sy=240.0;
- double leng0=400.0;
- double delta=0.0001;TRect rect;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //由不动点线形映射产生的分形图形(3)
- void __fastcall fractal(double x0,double y0,double x1,double y1,int n)
- {
- double px,py;
- int sign;
- if(n<=N)
- {sign=(n%2==0)?(-1):1;
- if((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)>=2.0)
- {px=x0+(a*(x1-x0)-b*sign*(y1-y0));
- py=y0+(b*sign*(x1-x0)+a*(y1-y0));
- Form1->Image1->Canvas->Pixels[px][-py]=clWhite;
- fractal(x0,y0,px,py,n+1);
- fractal(px,py,x1,y1,n+1);
- }
- }
- }
- 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)
- {
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- //设置原点
- SetWindowOrgEx(Image1->Canvas->Handle,0,0,NULL);
- SetViewportOrgEx(Image1->Canvas->Handle,sx,sy,NULL);
- a=0.5;
- b=t/2;
- Image1->Canvas->Pen->Color=clYellow;
- Image1->Canvas->Ellipse(-3,-3,3,3);
- Image1->Canvas->Pen->Color=clRed;
- Image1->Canvas->Ellipse(leng0-3,-3,leng0+3,3);
- fractal(0,0,leng0,0,1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------