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

分形几何

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fractus5_02.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. #include "glib.h"
  10. int A=1,B=0,C=1,MAX_COL=4,Y=256;
  11. double delta=0.0001;TRect rect;
  12. int colors[16]={0x00000000,0x00FF0000,0x0000FF00,0x00FF8C00,
  13.                 0x000000FF,0x00FF00FF,0x0000FFFF,0x00A0A0A0,
  14.                 0x009BFFFF,0x009BFFFF,0x00A0FF00,0x00FFFF00,
  15.                 0x006E6EFF,0x00FF9BFF,0x009BFFFF,0x00FFFFFF};
  16. //---------------------------------------------------------------------------
  17. __fastcall TForm1::TForm1(TComponent* Owner)
  18.         : TForm(Owner)
  19. {
  20. }
  21. //---------------------------------------------------------------------------
  22. //细胞自动装置(1)
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25.   Image1->Height=0;Image1->Top=0;
  26.   Image1->Width=Screen->Width;Image1->Height=Screen->Height;
  27.   rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
  28.   Image1->Canvas->CopyMode=cmBlackness;
  29.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  30. }
  31. //---------------------------------------------------------------------------
  32. void __fastcall TForm1::N1Click(TObject *Sender)
  33. {
  34.   int x,y;
  35.   static int f[640],g[640];
  36.   Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
  37.   set0(0,72);
  38.   for(x=0;x<640;x++)
  39.     if(x==320)
  40.      {f[x]=1;
  41.       putpixel(x,0,colors[f[x]]);
  42.      }
  43.     else f[x]=0;
  44.   for(y=1;y<Y;y++)
  45.    {for(x=0;x<640;x++)
  46.      {g[x]=(!x)?(B*f[x]+C*f[x+1])
  47.          :((x==639)?(A*f[x-1]+B*f[x]):(A*f[x-1]+B*f[x]+C*f[x+1]));
  48.       g[x]=(g[x]-1)%MAX_COL+1;
  49.       if(g[x])
  50.         putpixel(320+(x-320)/sqrt(3.0),y,colors[g[x]]);
  51.      }
  52.     for(x=0;x<640;x++)
  53.       f[x]=g[x];
  54.    }
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::N2Click(TObject *Sender)
  58. {
  59.   if(SavePictureDialog1->Execute())
  60.     Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::N3Click(TObject *Sender)
  64. {
  65.   Close();        
  66. }
  67. //---------------------------------------------------------------------------