fractus5_02.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:2k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus5_02.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- int A=1,B=0,C=1,MAX_COL=4,Y=256;
- double delta=0.0001;TRect rect;
- int colors[16]={0x00000000,0x00FF0000,0x0000FF00,0x00FF8C00,
- 0x000000FF,0x00FF00FF,0x0000FFFF,0x00A0A0A0,
- 0x009BFFFF,0x009BFFFF,0x00A0FF00,0x00FFFF00,
- 0x006E6EFF,0x00FF9BFF,0x009BFFFF,0x00FFFFFF};
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //细胞自动装置(1)
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Image1->Height=0;Image1->Top=0;
- Image1->Width=Screen->Width;Image1->Height=Screen->Height;
- rect=Rect(0,0,Image1->Width,Image1->Height);//清屏
- Image1->Canvas->CopyMode=cmBlackness;
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N1Click(TObject *Sender)
- {
- int x,y;
- static int f[640],g[640];
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- set0(0,72);
- for(x=0;x<640;x++)
- if(x==320)
- {f[x]=1;
- putpixel(x,0,colors[f[x]]);
- }
- else f[x]=0;
- for(y=1;y<Y;y++)
- {for(x=0;x<640;x++)
- {g[x]=(!x)?(B*f[x]+C*f[x+1])
- :((x==639)?(A*f[x-1]+B*f[x]):(A*f[x-1]+B*f[x]+C*f[x+1]));
- g[x]=(g[x]-1)%MAX_COL+1;
- if(g[x])
- putpixel(320+(x-320)/sqrt(3.0),y,colors[g[x]]);
- }
- for(x=0;x<640;x++)
- f[x]=g[x];
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------