fractus4_02.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:4k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus4_02.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- const int KL=100;
- const double BOX=0.01;
- const int UX=4;
- int d=160;
- double x_min=-2.0,x_max=2.0;
- double xc,yc,x0,y0;
- 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 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 sx,sy,i,j,k,k_max,prd,col;
- double a1,b1;
- double xx[20],yy[20],x[KL+1],y[KL+1];
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- set0(120.0,200.0);
- a1=2*(double)d/(x_max-x_min);
- b1=-(double)d*(x_max+x_min)/(x_max-x_min);
- Image1->Canvas->Pen->Color=colors[7];
- Image1->Canvas->Brush->Style=bsSolid;
- Image1->Canvas->Brush->Color=clBlack;
- for(sx=0;sx<=KL*UX;sx+=KL*UX/10)
- {if(sx==0||sx==KL*UX)
- Image1->Canvas->Pen->Style=psSolid;
- else
- Image1->Canvas->Pen->Style=psDot;
- Form1->Image1->Canvas->MoveTo(sx,-d);
- Form1->Image1->Canvas->LineTo(sx,d);
- }
- for(sy=-d;sy<=d;sy+=d/4)
- {if(sy==-d||sy==0||sy==d)
- Image1->Canvas->Pen->Style=psSolid;
- else
- Image1->Canvas->Pen->Style=psDot;
- Form1->Image1->Canvas->MoveTo(0,sy);
- Form1->Image1->Canvas->LineTo(KL*UX,sy);
- }
- 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)
- {k_max=k;prd=0;goto BR;}
- }
- k_max=KL;
- for(k=1;k<=13;k++)
- {if(fabs(x[k_max]-x[k_max-k])<BOX
- &&fabs(y[k_max]-y[k_max-k])<BOX)
- {prd=k;goto BR;}
- }
- prd=0;
- BR:for(k=0;k<=k_max;k++)
- {sx=a1*x[k]+b1;
- col=(prd)?(1+k%prd):15;
- Image1->Canvas->Pen->Color=colors[col];
- Image1->Canvas->Brush->Color=colors[col];
- Image1->Canvas->Ellipse(k*UX-2,-sx-2,k*UX+2,-sx+2);
- }
- for(k=0;k<prd;k++)
- {xx[k]=x[k_max-k];
- yy[k]=y[k_max-k];
- }
- for(i=0;i<prd-1;i++)
- {double s;
- for(j=i+1;j<prd;j++)
- if(xx[i]<xx[j])
- {s=xx[i];xx[i]=xx[j];xx[j]=s;
- s=yy[i];yy[i]=yy[j];yy[j]=s;
- }
- }
- }
- //---------------------------------------------------------------------------
- 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.6;yc=0;x0=0.2;y0=0.5;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- xc=-1.1;yc=0;x0=0.2;y0=0.2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- xc=-1.35;yc=0;x0=0.2;y0=0.05;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_4Click(TObject *Sender)
- {
- xc=-1.39;yc=0;x0=0.05;y0=0.02;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_5Click(TObject *Sender)
- {
- xc=-1.65;yc=0;x0=0.2;y0=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_6Click(TObject *Sender)
- {
- xc=-1.76;yc=0;x0=0.1;y0=0.04;
- }
- //---------------------------------------------------------------------------