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

分形几何

开发平台:

Visual C++

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