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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus2_09.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. #include "glib.h"
  10. int n_br=6;
  11. int n_st;
  12. double k,r0=180.0;
  13. int N;
  14. double delta=0.0001;TRect rect;
  15. int select;
  16. //---------------------------------------------------------------------------
  17. __fastcall TForm1::TForm1(TComponent* Owner)
  18.         : TForm(Owner)
  19. {
  20. }
  21. //---------------------------------------------------------------------------
  22. //基本图案的反复映像生成的分形图形(1)
  23. void __fastcall fractal(double leng,int n)
  24. {
  25.   int i,j;
  26.   if(n>=N||k<=1.0)
  27.     Form1->Image1->Canvas->Pixels[LPX][LPY]=clWhite;
  28.   else
  29.    {for(i=0;i<n_br;i++)
  30.      {if(!i) fractal(leng/k,n+1);
  31.       for(j=1;j<=n_st;j++)
  32.        {warp(leng*2/k);
  33.         fractal(leng/k,n+1);
  34.        }
  35.       turn(180.0);
  36.       warp(leng*2*n_st/k);
  37.       turn(180.0);
  38.       turn(360.0/n_br);
  39.      }
  40.    }
  41. }
  42. void __fastcall TForm1::FormCreate(TObject *Sender)
  43. {
  44.   Image1->Height=0;Image1->Top=0;
  45.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  46.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  47.   Image1->Canvas->CopyMode=cmBlackness;
  48.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::N1Click(TObject *Sender)
  52. {
  53.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  54.   k=2*n_st+1;
  55.   setlp(320.0,200.0);
  56.   setangle(90.0);
  57.   fractal(r0,0);
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::N2Click(TObject *Sender)
  61. {
  62.   if(SavePictureDialog1->Execute())
  63.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::N3Click(TObject *Sender)
  67. {
  68.   Close();        
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::N4_1Click(TObject *Sender)
  72. {
  73.  n_st=1;N=5;
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TForm1::N4_2Click(TObject *Sender)
  77. {
  78.   n_st=2;N=4;
  79. }
  80. //---------------------------------------------------------------------------