fractus3_05.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus3_05.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- int n_rot;
- int N;
- double ang,scale,ks;
- double r1;
- double delta=0.0001;TRect rect;
- int colors[16]={0x00000000,0x00FF0000,0x0000FF00,0x00FF8C00,
- 0x000000FF,0x00FF00FF,0x0000FFFF,0x00D7D7D7,
- 0x009BFFFF,0x009BFFFF,0x00A0FF00,0x00FFFF00,
- 0x006E6EFF,0x00FF9BFF,0x009BFFFF,0x00FFFFFF};
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //正多边形为构成元素的递归图形
- void __fastcall polygon(double r)
- {TPoint points[5];
- int i;
- turn(180.0);
- warp(r);
- turn(90.0+ang/2);
- for(i=0;i<n_rot;i++)
- {points[i]=Point(LPX,LPY);
- warp(2*r*ks);
- turn(ang);
- }
- turn(90-ang/2);
- warp(r);
- Form1->Image1->Canvas->Polygon(points,n_rot-1);
- }
- //---------------------------------------------------------------------------
- void __fastcall recurs(double r,int n)
- {
- int i,j,k;
- if(n<=N)
- {Form1->Image1->Canvas->Pen->Color=colors[n];
- Form1->Image1->Canvas->Brush->Color=colors[n];
- polygon(r);
- if(n==1)
- {j=n_rot;k=0;}
- else
- {j=n_rot-1;k=1;}
- for(i=0;i<j;i++)
- {turn(180.0);
- turn((i+k)*ang);
- warp(r*(1+scale));
- recurs(r*scale,n+1);
- turn(180.0);
- warp(r*(1+scale));
- turn(-(i+k)*ang);
- }
- }
- Form1->Image1->Canvas->Pen->Color=colors[n-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)
- {
- Image1->Canvas->CopyRect(rect,Image1->Canvas,rect);
- ang=360.0/n_rot;
- ks=sin(PI/n_rot);
- setlp(320.0,200.0);
- setangle(-90.0);
- recurs(r1,1);
- }
- //---------------------------------------------------------------------------
- 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)
- {
- n_rot=3;N=7;
- scale=0.63;r1=54.0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- n_rot=4;N=6;
- scale=0.5;r1=64.0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- n_rot=5;N=5;
- scale=0.38;r1=90.0;
- }
- //---------------------------------------------------------------------------