玩具箱---钟表的转动指针(c++)

1 篇文章 0 订阅
1 篇文章 0 订阅
#include<graphics.h>
#include<math.h>

//旋转圆心坐标
int const Point0_x = 300;
int const Point0_y = 300;
//旋转线段长度
int const Length = 100;

double const PI = 3.1415926;
//旋转速度参数
double const radian_v = PI/180;
//旋转端点初始位置
double RotateLocation_x = 500;
double RotateLocation_y = 300;
//旋转线段初始弧度参数
double radian = 0;
//三角形底部长和高
int TriangleBL = 15;
int TH = 20;

//等腰三角形底部两点坐标和顶部坐标
double Tbx_1, Tby_1, Tbx_2, Tby_2, Ttx_3, Tty_3;
//double Point[3] = ((x_1, y_1), (x_2, y_2), (x_3, y_3));

//三角形旋转
void Triangle() {
	//三角形底部一点
	Tbx_1 = RotateLocation_x + TriangleBL/2 * sin(radian);
	Tby_1 = RotateLocation_y - TriangleBL/2 * cos(radian);
	//三角形底部另一点
	Tbx_2 = RotateLocation_x - TriangleBL/2 * sin(radian);
	Tby_2 = RotateLocation_y + TriangleBL/2 * cos(radian);
	//三角形顶部点
	Ttx_3 = Point0_x + (Length + TH) * cos(radian);
	Tty_3 = Point0_y + (Length + TH) * sin(radian);

	/*
	line(Tbx_1, Tby_1, Tbx_2, Tby_2);
	line(Tbx_2, Tby_2, Ttx_3, Tty_3);
	line(Ttx_3, Tty_3, Tbx_1, Tby_1);
	*/

	//三角形三点位置
	POINT point_1[3] = { {Tbx_1, Tby_1},{Tbx_2, Tby_2},{Ttx_3, Tty_3} };
	//绘制三角形
	fillpolygon(point_1, 3);	
}

//线段旋转
void LineRotate() {
	//线段一边坐标
	RotateLocation_x = Point0_x + Length * cos(radian);
	RotateLocation_y = Point0_x + Length * sin(radian);
	//绘制指针线段
	line(Point0_x, Point0_y, RotateLocation_x, RotateLocation_y);
}

int main() {
	//绘制图板
	initgraph(800, 800);
	//设置填充色
	setfillcolor(WHITE);
	//
	while (true)
	{
		LineRotate();
		Triangle();
		//角度递增
		radian = radian + radian_v;

		Sleep(100);
		//用当前背景色重画图板
		cleardevice();
	}
}

钟表指针

0123456789;

0123456789;

0123456789;

0123456789;

0123456789;

0123456789;

0123456789;

0123456789;

0123456789;

0123456789;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值