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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus2_10_b.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. #include "glib.h"
  10. int n_br=4;
  11. int n_st=8;
  12. double k,r0=180.0;
  13. double scale=0.6;
  14. double ang=25.0;
  15. double delta=0.0001;TRect rect;
  16. //---------------------------------------------------------------------------
  17. __fastcall TForm1::TForm1(TComponent* Owner)
  18.         : TForm(Owner)
  19. {
  20. }
  21. //---------------------------------------------------------------------------
  22. //分形状宇宙
  23. void __fastcall fractal(double leng,double angle)
  24. {
  25.   int i,j;double s;
  26.   s=1;
  27.   if(leng<=k/2||k<=1.0)
  28.     Form1->Image1->Canvas->Pixels[LPX][LPY]=clWhite;
  29.   else
  30.    {for(i=0;i<n_br;i++)
  31.      {if(!i)
  32.        {turn(-angle/2);
  33.         fractal(leng/k,angle);
  34.         turn(angle/2);
  35.        }
  36.       for(j=1;j<=n_st;j++,s*=scale)
  37.        {warp(leng*s/k);
  38.         warp(leng*s*scale/k);
  39.         turn(angle/2);
  40.         fractal(leng*s*scale/k,angle/2);
  41.         turn(angle/2);
  42.        }
  43.       turn(180.0);
  44.       for(j=n_st;j>=1;j--,s/=scale)
  45.        {turn(-angle);
  46.         warp(leng*s/k);
  47.         warp(leng*s/(scale*k));
  48.        }
  49.       turn(180.0);
  50.       turn(360.0/n_br);
  51.      }
  52.    }
  53. }
  54. void __fastcall TForm1::FormCreate(TObject *Sender)
  55. {
  56.   Image1->Height=0;Image1->Top=0;
  57.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  58.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  59.   Image1->Canvas->CopyMode=cmBlackness;
  60.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::N1Click(TObject *Sender)
  64. {
  65.   int i;
  66.   double a,b;
  67.   double s;
  68.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  69.   setlp(0.0,0.0);setangle(0.0);
  70.   s=1;
  71.   for(i=1;i<=n_st;i++,s*=scale)
  72.    {warp(s);
  73.     a=s*scale;
  74.     warp(a);
  75.     b=sqrt(LPX*LPX+LPY*LPY);
  76.     if(k<a+b) k=a+b;
  77.     turn(ang);
  78.    }
  79.   setlp(320.0,200.0);
  80.   setangle(90.0);
  81.   fractal(r0,ang);
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::N2Click(TObject *Sender)
  85. {
  86.   if(SavePictureDialog1->Execute())
  87.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::N3Click(TObject *Sender)
  91. {
  92.   Close();        
  93. }
  94. //---------------------------------------------------------------------------