fractus2_06A.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus2_06A.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- double a,b,t=0.5;
- double sx=220.0,sy=280.0;
- double leng0=200.0;
- double delta=0.0001;TRect rect;
- int select;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //由不动点线形映射产生的分形图形(1A,2A)
- void __fastcall fractal(double x0,double y0,double x1,double y1)
- {
- double px,py;
- if((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)>=2.0)
- {px=x0+(a*(x1-x0)-b*(y1-y0));
- py=y0+(b*(x1-x0)+a*(y1-y0));
- Form1->Image1->Canvas->Pixels[px][-py]=clWhite;
- fractal(x0,y0,px,py);
- if(select==1) fractal(px,py,x1,y1);
- else fractal(x1,y1,px,py);
- }
- }
- 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=1/(1+t*t);
- b=t/(1+t*t);
- 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);
- }
- //---------------------------------------------------------------------------
- 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)
- {
- select=1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- select=2;
- }
- //---------------------------------------------------------------------------