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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "koch.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. #include "glib.h"
  10. int N=5;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13.         : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall koch(double leng,int n)
  18. {
  19.   if(n>=N)
  20.     move(leng);
  21.   else
  22.    {koch(leng/3,n+1);
  23.     turn(60.0);
  24.     koch(leng/3,n+1);
  25.     turn(-120.0);
  26.     koch(leng/3,n+1);
  27.     turn(60.0);
  28.     koch(leng/3,n+1);
  29.    }
  30. }
  31. void __fastcall TForm1::FormCreate(TObject *Sender)
  32. {
  33.   Image1->Height=0;Image1->Top=0;
  34.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  35.   Image1->Canvas->Pen->Color=clGreen;
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TForm1::N1Click(TObject *Sender)
  39. {
  40.   setlp(120.0,240.0);
  41.   setangle(0.0);
  42.   koch(400.0,0);
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::N2Click(TObject *Sender)
  46. {
  47.   if(SavePictureDialog1->Execute())
  48.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::N3Click(TObject *Sender)
  52. {
  53.   Close();
  54. }
  55. //---------------------------------------------------------------------------