fractus3_01.cpp
资源名称:fenxin.rar [点击查看]
上传用户:hzcygd
上传日期:2022-04-30
资源大小:109k
文件大小:3k
源码类别:
分形几何
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "fractus3_01.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- #include "glib.h"
- int N=7;
- double sx=320.0,sy=390.0;
- double leng1;
- double (*branch)[2];
- double branch_1[][2]={{30.0,0.7},{-30.0,0.7},END};
- double branch_2[][2]={{20.0,0.7},{-30.0,0.6},END};
- double branch_3[][2]={{45.0,0.7},{15.0,0.7},{-15.0,0.7},{-45.0,0.7},END};
- 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 tree(double leng,int n)
- {
- int i=0;
- if(n<=N)
- {Form1->Image1->Canvas->Pen->Color=colors[n];
- if(n==1)
- {move(leng);
- tree(leng,n+1);
- }
- else
- while((branch[i][0]-END)>delta||(branch[i][0]-END)<-delta)
- {turn(branch[i][0]);
- move(branch[i][1]*leng);
- tree(branch[i][1]*leng,n+1);
- turn(180.0);
- warp(branch[i][1]*leng);
- turn(180-branch[i][0]);
- i++;
- }
- }
- else
- {Form1->Image1->Canvas->Pen->Color=clWhite;
- warp(leng*0.3);
- Form1->Image1->Canvas->Ellipse(LPX-leng*0.3,LPY-leng*0.3,
- LPX+leng*0.3,LPY+leng*0.3);
- turn(180.0);
- warp(leng*0.3);
- turn(180.0);
- }
- 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);
- setlp(sx,sy);
- setangle(90.0);
- tree(leng1,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)
- {
- leng1=120.0;branch=branch_1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_2Click(TObject *Sender)
- {
- leng1=130.0;branch=branch_2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::N4_3Click(TObject *Sender)
- {
- leng1=120.0;branch=branch_3;
- }
- //---------------------------------------------------------------------------