fractus2_06A.cpp
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus2_06A.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. #include "glib.h"
  10. double a,b,t=0.5;
  11. double sx=220.0,sy=280.0;
  12. double leng0=200.0;
  13. double delta=0.0001;TRect rect;
  14. int select;
  15. //---------------------------------------------------------------------------
  16. __fastcall TForm1::TForm1(TComponent* Owner)
  17.         : TForm(Owner)
  18. {
  19. }
  20. //---------------------------------------------------------------------------
  21. //由不动点线形映射产生的分形图形(1A,2A)
  22. void __fastcall fractal(double x0,double y0,double x1,double y1)
  23. {
  24.   double px,py;
  25.   if((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)>=2.0)
  26.    {px=x0+(a*(x1-x0)-b*(y1-y0));
  27.     py=y0+(b*(x1-x0)+a*(y1-y0));
  28.     Form1->Image1->Canvas->Pixels[px][-py]=clWhite;
  29.     fractal(x0,y0,px,py);
  30.     if(select==1) fractal(px,py,x1,y1);
  31.     else fractal(x1,y1,px,py);
  32.    }
  33. }
  34. void __fastcall TForm1::FormCreate(TObject *Sender)
  35. {
  36.   Image1->Height=0;Image1->Top=0;
  37.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  38.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  39.   Image1->Canvas->CopyMode=cmBlackness;
  40.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::N1Click(TObject *Sender)
  44. {
  45.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  46.   //设置原点
  47.   SetWindowOrgEx(Image1->Canvas->Handle,0,0,NULL);
  48.   SetViewportOrgEx(Image1->Canvas->Handle,sx,sy,NULL);
  49.   a=1/(1+t*t);
  50.   b=t/(1+t*t);
  51.   Image1->Canvas->Pen->Color=clYellow;
  52.   Image1->Canvas->Ellipse(-3,-3,3,3);
  53.   Image1->Canvas->Pen->Color=clRed;
  54.   Image1->Canvas->Ellipse(leng0-3,-3,leng0+3,3);
  55.   fractal(0,0,leng0,0);
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::N2Click(TObject *Sender)
  59. {
  60.   if(SavePictureDialog1->Execute())
  61.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::N3Click(TObject *Sender)
  65. {
  66.   Close();        
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::N4_1Click(TObject *Sender)
  70. {
  71.   select=1;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TForm1::N4_2Click(TObject *Sender)
  75. {
  76.   select=2;
  77. }
  78. //---------------------------------------------------------------------------