fractus4_03_b.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:5k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus4_03_b.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- const int KL=100;
- const double BOX=0.01;
- const int STEP=4;
- int sx,sy,dx=192,dy=192;
- double x_min=-2.0,x_max=2.0,y_min=-2.0,y_max=2.0;
- double xc,yc,x0,y0;
- double a1,b1,a2,b2;
- 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)
- {
- }
- //---------------------------------------------------------------------------
- //Zc为复数的朱利亚集合
- 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;
- }
- //---------------------------------------------------------------------------
- void __fastcall plot(int col)
- {putpixel(sx,-sy,colors[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)
- return;
- }
- for(k=1;k<=13;k++)
- {if(fabs(x[KL]-x[KL-k])<BOX
- &&fabs(y[KL]-y[KL-k])<BOX)
- {plot(k);return;}
- }
- plot(15);
- }
- //---------------------------------------------------------------------------
- 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();
- Image1->Canvas->Pen->Color=colors[7];
- Image1->Canvas->Pen->Style=psSolid;
- Image1->Canvas->Brush->Style=bsSolid;
- Image1->Canvas->Brush->Color=clBlack;
- Image1->Canvas->Rectangle(-dx,-dy,dx,dy);
- Image1->Canvas->Pen->Style=psDot;
- for(sx=-dx+dx/4;sx<dx;sx+=dx/4)
- {Form1->Image1->Canvas->MoveTo(sx,-dy);
- Form1->Image1->Canvas->LineTo(sx,dy);
- }
- for(sy=-dy+dy/4;sy<dy;sy+=dy/4)
- {Form1->Image1->Canvas->MoveTo(-dx,sy);
- Form1->Image1->Canvas->LineTo(dx,sy);
- }
- for(sx=0;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)
- {
- xc=0;yc=0.6;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- xc=-1.1;yc=0.2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- xc=-0.1;yc=0.77;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_4Click(TObject *Sender)
- {
- xc=0.3;yc=0.5;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_5Click(TObject *Sender)
- {
- xc=-0.52;yc=0.55;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_6Click(TObject *Sender)
- {
- xc=-1.15;yc=0.25;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_7Click(TObject *Sender)
- {
- xc=0.12;yc=0.61;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_8Click(TObject *Sender)
- {
- xc=-0.37;yc=0.61;
- }
- //---------------------------------------------------------------------------