fractus4_05_b.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:5k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus4_05_b.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- const int KL=300;
- const double BOX=0.01;
- const int STEP=4;
- int sx,sy,dx=192,dy=192;
- double x_min,x_max,y_min,y_max;
- double x0,y0,xc,yc;
- double a1,b1,a2,b2;
- int (*col)[2];
- int col_1[][2]={{2,2},{4,4},{8,1},{16,6},{32,3},{KL+1,5}},
- col_2[][2]={{2,1},{4,2},{8,4},{16,3},{32,5},{KL+1,6}},
- col_3[][2]={{2,4},{4,1},{8,2},{16,5},{32,6},{KL+1,3}},
- col_4[][2]={{2,2},{4,5},{8,3},{16,4},{32,1},{KL+1,6}},
- col_5[][2]={{2,1},{4,6},{8,3},{16,4},{36,2},{81,5},{KL+1,7}},
- col_6[][2]={{2,3},{4,6},{8,5},{16,2},{32,4},{64,1},{KL+1,7}};
- 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)
- {
- }
- //---------------------------------------------------------------------------
- //按发散区域分类的朱利亚集合
- void __fastcall coord(void)
- {a1=(x_max-x_min)/(2*dx);
- b1=(x_max+x_min)/2;
- a2=(y_max-y_min)/(2*dy);
- b2=(y_max+y_min)/2;
- }
- //---------------------------------------------------------------------------
- int __fastcall getcol(int k)
- {int i=0;
- while(k>col[i][0]&&k<=KL)
- i++;
- return col[i][1];
- }
- //---------------------------------------------------------------------------
- void __fastcall plot(int col)
- {putpixel(sx,-sy,colors[col]);
- }
- //---------------------------------------------------------------------------
- void julia(void)
- {int k;double s;
- static double x[KL+1],y[KL+1];
- x[0]=x0;y[0]=y0;
- for(k=1;k<=KL;k++)
- {x[k]=x[k-1]*x[k-1]-y[k-1]*y[k-1]+xc;
- y[k]=2*x[k-1]*y[k-1]+yc;
- if((x[k]*x[k]+y[k]*y[k])>=4.0)
- {plot(getcol(k));return;}
- }
- }
- //---------------------------------------------------------------------------
- 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)
- {
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- set0(320,200);
- coord();
- for(sx=-dx;sx<=dx;sx+=STEP)
- {x0=a1*sx+b1;
- for(sy=-dy;sy<=dy;sy+=STEP)
- {y0=a2*sy+b2;
- julia();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N2Click(TObject *Sender)
- {
- if(SavePictureDialog1->Execute())
- Image1->Picture->SaveToFile(SavePictureDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N3Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_1Click(TObject *Sender)
- {
- x_min=-1.4;x_max=1.4;
- y_min=-1.4;y_max=1.4;
- xc=0.38;yc=0.15;
- col=col_1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- x_min=-1.6;x_max=1.6;
- y_min=-1.6;y_max=1.6;
- xc=-0.704;yc=0.28;
- col=col_2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- x_min=-0.27;x_max=0.13;
- y_min=0.51;y_max=0.91;
- xc=-0.704;yc=0.28;
- col=col_2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_4Click(TObject *Sender)
- {
- x_min=-0.76;x_max=0.76;
- y_min=-0.76;y_max=0.76;
- xc=-1.27;yc=0.04;
- col=col_3;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_5Click(TObject *Sender)
- {
- x_min=-1.5;x_max=1.5;
- y_min=-1.5;y_max=1.5;
- xc=-0.035;yc=0.795;
- col=col_4;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_6Click(TObject *Sender)
- {
- x_min=-0.38;x_max=0.12;
- y_min=0.65;y_max=1.15;
- xc=0.035;yc=0.795;
- col=col_4;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_7Click(TObject *Sender)
- {
- x_min=-1.6;x_max=1.6;
- y_min=-1.6;y_max=1.6;
- xc=-0.6;yc=0.425;
- col=col_5;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_8Click(TObject *Sender)
- {
- x_min=-1.5;x_max=1.5;
- y_min=-1.5;y_max=1.5;
- xc=-0.23;yc=0.67;
- col=col_6;
- }
- //---------------------------------------------------------------------------