⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmpanimate.cpp

📁 C++ Builder 6 编程实例教程-北京希望电子出版社出版
💻 CPP
字号:
//---------------------------------------------------------------------------
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -