bmpanimate.cpp

来自「C++ Builder 6 编程实例教程-北京希望电子出版社出版」· C++ 代码 · 共 49 行

CPP
49
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "math.h"
#include "BmpAnimate.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
float a;
//变量声明
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Form1->Timer1->Enabled=false;
//设置Timer1控件处于无效的状态
a=0;
//变量初始化
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Image2->Left=Image1->Left+Image1->Width/2+150*cos(a)-Image2->Width/2;
//计算地球的横坐标
Image2->Top=Image1->Top+Image1->Height/2+150*sin(a)-Image2->Height/2;
//计算地球的纵坐标
Image3->Left=Image2->Left+Image2->Width/2+50*cos(5*a)-Image3->Width/2;
//计算月亮的横坐标
Image3->Top=Image2->Top+Image2->Height/2+50*sin(5*a)-Image3->Height/2;
//计算月亮的纵坐标
a=a-3.1415926 / 90;
//角度的变化幅度为20度
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClick(TObject *Sender)
{
Form1->Timer1->Enabled=true;
//开始动画
}
//---------------------------------------------------------------------------
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?