- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "math.h"
- #include "Art.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Form1->Image1->Visible=false;
- Form1->Image2->Visible=false;
- //设置图象控件都处于不可见状态
- Form1->Image1->Transparent=true;
- Form1->Image2->Transparent=true;
- //设置图象的背景色为透明
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- float x1[120];
- float y1[120];
- float x2[120];
- float y2[120];
- float pi;
- int n;
- int r;
- float a;
- int i;
- float t;
- float x;
- float y;
- int k;
- //变量定义
- Form1->Image1->Visible=true;
- Form1->Image2->Visible=false;
- //设置控件可见性
- pi=3.1415926;
- n=50;
- r=280;
- i=0;
- a=0;
- //变量赋值
- for (i=1;i<120;i++)
- {
- x1[i]=r*cos(a);
- y1[i]=(-1)*r*sin(a)/2;
- a=a+pi/60;
- }
- r=100;
- i=0;
- a=0;
- for (i=0;i<=120;i++)
- {
- t=(r*(1+1/2*sin(12*a)))*(1/2+1/2*sin(4*a));
- x2[i]=t*cos(a);
- y2[i]=(-1)*t*sin(a)/2;
- a=a+pi/60;
- }
- for (k=0;k<=n;k++)
- {
- for(i=0;i<=120;i++)
- {
- x=(x2[i]-x1[i])/n*k+x1[i];
- y=(y2[i]-y1[i])/n*k+y1[i];
- x=x+300;
- y=y+150;
- if (i==0)
- {
- Form1->Image1->Canvas->MoveTo((x/2),(y));
- }
- Form1->Image1->Canvas->LineTo((x*1.1/2),(y));
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- float t,x0,y0;
- float r;
- int n,j,i;
- float x[50];
- float y[50];
- //变量定义
- Form1->Image2->Visible=true;
- Form1->Image1->Visible=false;
- //设置控件可见性
- n=25;
- //设置分段数
- t=6.28318/n;
- r=130;
- //设置半径
- x0= 180;
- y0= 150;
- //设置图案的中心点
- for (i=0;i<=n;i++)
- {
- x[i]=r*cos(i*t)+x0;
- y[i]=r*sin(i*t)+y0;
- //通过循环求出"金刚石" 图案的坐标点
- }
- for (i=0;i<=n;i++)
- {
- for(j=i+1;j<=n-1;j++)
- {
- Form1->Image2->Canvas->MoveTo((x[i]),(y[i]));
- Form1->Image2->Canvas->LineTo((x[j]),(y[j]));
- //连线
- }
- }
- }