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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus3_03.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;
  12. double ang,scale;
  13. double r1;
  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,j,k;
  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.     if(n==1)
  34.      {j=n_rot;k=0;}
  35.     else
  36.      {j=3;k=1;}
  37.     for(i=0;i<j;i++)
  38.      {turn((i-k)*ang);
  39.       warp(r*(1+scale));
  40.       recurs(r*scale,n+1);
  41.       turn(180.0);
  42.       warp(r*(1+scale));
  43.       turn(180-(i-k)*ang);
  44.      }
  45.    }
  46.   Form1->Image1->Canvas->Pen->Color=colors[n-1];
  47. }
  48. void __fastcall TForm1::FormCreate(TObject *Sender)
  49. {
  50.   Image1->Height=0;Image1->Top=0;
  51.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  52.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  53.   Image1->Canvas->CopyMode=cmBlackness;
  54.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::N1Click(TObject *Sender)
  58. {
  59.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  60.   ang=360.0/n_rot;
  61.   setlp(320.0,200.0);
  62.   setangle(90.0);
  63.   recurs(r1,1);
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::N2Click(TObject *Sender)
  67. {
  68.   if(SavePictureDialog1->Execute())
  69.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::N3Click(TObject *Sender)
  73. {
  74.   Close();        
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::N4_1Click(TObject *Sender)
  78. {
  79.   n_rot=4;N=6;
  80.   scale=0.5;r1=64.0;
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TForm1::N4_2Click(TObject *Sender)
  84. {
  85.   n_rot=5;N=5;
  86.   scale=0.44;r1=70.0;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TForm1::N4_3Click(TObject *Sender)
  90. {
  91.   n_rot=6;N=5;
  92.   scale=0.42;r1=80.0;
  93. }
  94. //---------------------------------------------------------------------------