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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus3_04.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. #include "glib.h"
  10. int n_rot;
  11. int N=4;
  12. double ang,scale;
  13. double r1=180.0;
  14. double delta=0.0001;TRect rect;
  15. int colors[16]={0x00000000,0x00FF0000,0x0000FF00,0x00FF8C00,
  16.                 0x000000FF,0x00FF00FF,0x0000FFFF,0x00D7D7D7,
  17.                 0x009BFFFF,0x009BFFFF,0x00A0FF00,0x00FFFF00,
  18.                 0x006E6EFF,0x00FF9BFF,0x009BFFFF,0x00FFFFFF};
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner)
  21.         : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. //曼陀罗式递归图形
  26. void __fastcall recurs(double r,int n)
  27. {
  28.   int i;
  29.   if(n<=N)
  30.    {Form1->Image1->Canvas->Pen->Color=colors[n];
  31.     Form1->Image1->Canvas->Brush->Color=colors[n];
  32.     Form1->Image1->Canvas->Ellipse(LPX-r,LPY-r,LPX+r,LPY+r);
  33.     recurs(r*(1-2*scale),n+1);
  34.     for(i=0;i<n_rot;i++)
  35.      {turn(i*ang);
  36.       warp(r*(1-scale));
  37.       recurs(r*scale,n+1);
  38.       turn(180.0);
  39.       warp(r*(1-scale));
  40.       turn(180-i*ang);
  41.      }
  42.    }
  43.   Form1->Image1->Canvas->Pen->Color=colors[n-1];
  44. }
  45. void __fastcall TForm1::FormCreate(TObject *Sender)
  46. {
  47.   Image1->Height=0;Image1->Top=0;
  48.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  49.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  50.   Image1->Canvas->CopyMode=cmBlackness;
  51.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::N1Click(TObject *Sender)
  55. {
  56.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  57.   ang=360.0/n_rot;
  58.   if(n_rot!=4)
  59.     scale=sin(PI/n_rot)/(1+sin(PI/n_rot));
  60.   setlp(320.0,200.0);
  61.   setangle(90.0);
  62.   recurs(r1,1);
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm1::N2Click(TObject *Sender)
  66. {
  67.   if(SavePictureDialog1->Execute())
  68.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::N3Click(TObject *Sender)
  72. {
  73.   Close();        
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TForm1::N4_1Click(TObject *Sender)
  77. {
  78.   n_rot=6;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::N4_2Click(TObject *Sender)
  82. {
  83.   n_rot=8;
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TForm1::N4_3Click(TObject *Sender)
  87. {
  88.   n_rot=4;scale=1.0/3;
  89. }
  90. //---------------------------------------------------------------------------