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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus3_02.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 leng1;
  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 leng,int n)
  27. {
  28.   int i;double s;
  29.   if(n<=N)
  30.    {Form1->Image1->Canvas->Pen->Color=colors[n];
  31.     for(i=0;i<n_rot;i++)
  32.      {s=(n!=1&&!(n_rot%2))?((i+0.5)*ang):(i*ang);
  33.       turn(s);
  34.       move(leng);
  35.       recurs(leng*scale,n+1);
  36.       turn(180.0);
  37.       warp(leng);
  38.       turn(180-s);
  39.      }
  40.    }
  41.   Form1->Image1->Canvas->Pen->Color=colors[n-1];
  42. }
  43. void __fastcall TForm1::FormCreate(TObject *Sender)
  44. {
  45.   Image1->Height=0;Image1->Top=0;
  46.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  47.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  48.   Image1->Canvas->CopyMode=cmBlackness;
  49.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TForm1::N1Click(TObject *Sender)
  53. {
  54.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  55.   ang=360.0/n_rot;
  56.   setlp(320.0,200.0);
  57.   setangle(90.0);
  58.   recurs(leng1,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. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::N4_1Click(TObject *Sender)
  73. {
  74.   n_rot=5;N=5;
  75.   scale=0.38;leng1=120.0;
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TForm1::N4_2Click(TObject *Sender)
  79. {
  80.   n_rot=6;N=5;
  81.   scale=0.34;leng1=130.0;
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::N4_3Click(TObject *Sender)
  85. {
  86.   n_rot=8;N=4;
  87.   scale=0.28;leng1=140.0;        
  88. }
  89. //---------------------------------------------------------------------------