📄 mainform.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainForm.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
RotatePoints();
if(TextZoom)
{
if(TextSize<=50)
{
ShowText(TextPosition.x,TextPosition.y,TextSize);
TextSize+=3;
}
else
TextZoom=false;
}
else
{
if(TextSize>0)
{
ShowText(TextPosition.x,TextPosition.y,TextSize);
TextSize-=3;
}
else
TextZoom=true;
}
Invalidate();
}
//---------------------------------------------------------------------
void __fastcall TForm1::RotatePoints()
{
const float M_2PI = 2 * M_PI; // 2 pi radians in a circle
float StepAngle = M_2PI / PointCount; // 相邻节点间的夹角弧度
Rotation += M_PI / 32; // 起始旋转角度
if (Rotation > StepAngle) // 如果起始旋转角度大于两点的夹角
Rotation -= StepAngle; // 那么保持起始旋转角度不超过两点的夹角
// 下面的循环中,循环变量i用来遍历节点数组中所有节点,循环变量j用来增加每一个
// 节点的旋转角度,将其起始旋转角度设置为Rotation,可以保持图形的顺时针旋转,
// 旋转的增量为两点间的夹角
int i;
float j;
for (i = 0, j = Rotation; i < PointCount; i++, j += StepAngle) {
Points[i].X = cos(j);
Points[i].Y = sin(j);
//上述坐标将用来和当前的半径相乘
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Canvas->Pen->Color = clTeal;
Rotation = 0;
PointCount = MaxPoints;
TextSize=0;
TextZoom=true;
TextPosition.x=ClientWidth*3/4;
TextPosition.y=ClientHeight/2;
Label1->Caption=Edit2->Text;
CheckBox1->Checked=true;
RotatePoints();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
int centerX = ClientWidth / 2;
int centerY = ClientHeight / 2;
int radius = min(centerY, centerX);
int i,j;
for (i = 0; i < PointCount; i++) {
for (j = i + 1; j < PointCount; j++) {
Canvas->MoveTo(radius + floor(Points[i].X * radius),
radius + floor(Points[i].Y * radius));
Canvas->LineTo(radius + floor(Points[j].X * radius),
radius + floor(Points[j].Y * radius));
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
TextPosition.x=ClientWidth*3/4;
TextPosition.y=ClientHeight/2;
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
Timer1->Interval=StrToInt(Edit1->Text);
}
//---------------------------------------------------------------------------
void TForm1::ShowText(int X, int Y, int Size)
{
Label1->Left=X;
Label1->Top=Y;
Label1->Font->Size=Size;
}
void __fastcall TForm1::Edit2Change(TObject *Sender)
{
Label1->Caption=Edit2->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
TextPosition.x=X;
TextPosition.y=Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
Timer1->Enabled=CheckBox1->Checked;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -