实时钟表的实现

利用easyx在c语言代码下实现和现在时间完全相同的钟表
easyx软件可以直接搜,在官网上进行下载。
只能在windows平台下实现

代码如下:
game.h:

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>

#define HIGH 480
#define WIDTH 640
#define PI 3.1415926

test.cpp:

#include "game.h"
int main()
{
	initgraph(WIDTH,HIGH);
	int center_x = WIDTH / 2;
	int center_y = HIGH / 2;
	int secondLength = WIDTH / 5;
	int secondEnd_x;
	int secondEnd_y;
	float secondAngle = 0;

	int minuteLength = WIDTH / 6;
	int minuteEnd_x;
	int minuteEnd_y;
	float minuteAngle = 0;

	int hourLength = WIDTH / 10;
	int hourEnd_x;
	int hourEnd_y;
	float hourAngle = 0;
	SYSTEMTIME ti;

	setcolor(WHITE);
	circle(center_x, center_y, WIDTH / 4);
	BeginBatchDraw();
	while (1)
	{
		GetLocalTime(&ti);
		secondAngle = ti.wSecond * 2 * PI / 60;
		minuteAngle = ti.wMinute * 2 * PI / 60;
		hourAngle = ti.wHour * 2 * PI / 60;

		secondEnd_x = center_x + secondLength * sin(secondAngle);
		secondEnd_y = center_y - secondLength * cos(secondAngle);
		minuteEnd_x = center_x + minuteLength * sin(minuteAngle);
		minuteEnd_y = center_y - minuteLength * cos(minuteAngle);
		hourEnd_x = center_x + hourLength * sin(hourAngle);
		hourEnd_y = center_y - hourLength * cos(hourAngle);
		setcolor(WHITE);
		line(center_x, center_y, secondEnd_x, secondEnd_y);
		setcolor(YELLOW);
		line(center_x, center_y, minuteEnd_x, minuteEnd_y);
		setcolor(RED);
		line(center_x, center_y, hourEnd_x, hourEnd_y);

		FlushBatchDraw();
		Sleep(50);

		setcolor(BLACK);
		line(center_x, center_y, secondEnd_x, secondEnd_y);
		line(center_x, center_y, minuteEnd_x, minuteEnd_y);
		line(center_x, center_y, hourEnd_x, hourEnd_y);
		
	}

	EndBatchDraw();

	_getch();
	closegraph();
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值