//---------------------------------------------------------------------------
#include <vcl.h> #include <math.h>
#pragma hdrstop
#include <algorithm>
using std::min;
using std::max;
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
using namespace Gdiplus;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DoubleBuffered = true;
// 初始化GDI+
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
// 闭关GDI+
GdiplusShutdown(gdiplusToken);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
const static int OX = 200, OY = 200;
const static REAL C = 140;
const static REAL PI = 3.14;
static REAL offset = 0;
POINT p[4];
REAL k[4];
// 生成正文形四角的新坐标值
for (int i=0; i < 4; i++)
{
k[i] = offset + (PI / 2) * i;
p[i].x = (int)OX + C * sin(k[i]);
p[i].y = (int)OY + C * cos(k[i]);
}
Gdiplus::Graphics g(Canvas->Handle);
g.SetSmoothingMode(SmoothingModeHighQuality); //高画质、低速
// 重新填充背景
SolidBrush brush(Color::Color(0,0,0));
Pen pen(Color::Color(255, 255, 0), 3);
g.FillRectangle(&brush, 0, 0, ClientWidth, ClientHeight);
Gdiplus::Point point1(p[0].x, p[0].y);
Gdiplus::Point point2(p[1].x, p[1].y);
Gdiplus::Point point3(p[2].x, p[2].y);
Gdiplus::Point point4(p[3].x, p[3].y);
Gdiplus::Point point5(p[0].x, p[0].y);
// 在新坐标绘画正方形
Gdiplus::Point points[] = {point1, point2, point3, point4, point5};
g.DrawLines(&pen, points, 5);
offset += 0.1;
}
//--------------------------------------------------------------------------- |