吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5767|回复: 6
收起左侧

[C&C++ 转载] c语言编写的简易时钟

[复制链接]
余辉 发表于 2016-12-8 14:47
[C] 纯文本查看 复制代码
#include <graphics.h>

#include <math.h>

#include <conio.h>

#define PI 3.141592654

void Draw_Dial();//绘制静态的表盘

void Draw_Hand(int hour, int minute, int secend); //绘制表针

//主函数

int main()

{

initgraph(640, 480);//初始化一个图形界面 640*480

//circle(320,240,150);//画圆的函数

//rectangle(0, 0, 50, 50);//画正方体的函数

Draw_Dial();

setwritemode(R2_XORPEN);//设置XOR绘图模式

SYSTEMTIME time;//定义一个时间结构体 用来保存当前的时间

while (!_kbhit())

{

GetLocalTime(&time);//获取当前的时间

Draw_Hand(time.wHour,time.wMinute,time.wSecond); //把表针绘制出来

Sleep(1000);//间隔1秒 1000毫秒

Draw_Hand(time.wHour, time.wMinute, time.wSecond); //把表针绘制出来

}

closegraph();//关闭图形界面

return 0;

}

//绘制静态的表盘

void Draw_Dial()

{

//绘制边界

setcolor(GREEN);

circle(320, 240, 160);//画圆函数的参数 320 240坐标 160是圆的半径大小

circle(320, 240, 60);

circle(320, 240, 2);

//图形界面的输出文本信息 txt text 文字

outtextxy(260,420,L"GOOD GOOD STUDY");

outtextxy(283, 440, L"DAY DAY UP");

//line(0, 0, 639, 479);

//绘制刻度

//circle(320, 85, 2);

setcolor(WHITE);

int x, y;

for (int i = 0; i < 60; i++)

{

x = 320 + int(145 * sin(PI * 2 * i / 60));

y = 240 + int(145 * cos(PI * 2 * i / 60));

if (i % 15 == 0)

bar(x - 5, y - 5, x + 5, y + 5);

else if (i % 5 == 0)

circle(x, y, 3);

else

putpixel(x, y, WHITE); //点

}

}

//绘制表针

void Draw_Hand(int hour, int minute, int second)

{

double h_hour, h_minute, h_second; //三个弧度值

int x_hour, y_hour, x_minute, y_minute, x_second, y_second; //末端位置

//计算弧度值

h_second = second * 2 * PI / 60;

h_minute = minute * 2 * PI / 60 + h_second / 60;

h_hour = hour * 2 * PI / 12 + h_minute / 12;

//计算末端位置

x_second = int(120 * sin(h_second)); y_second=int(120 * cos(h_second));

x_minute = int(100 * sin(h_minute)); y_minute = int(100 * cos(h_minute));

x_hour = int(70 * sin(h_hour)); y_hour = int(70 * cos(h_hour));

//绘制秒针

setlinestyle(PS_SOLID, 2); //PS_SOILD 实线 2像素 线条的粗细

setcolor(RED);

line(320 + x_second, 240 - y_second, 320 - x_second / 3, 240 + y_second / 3);

//绘制分针

setlinestyle(PS_SOLID, 6); //PS_SOILD 实线 2像素 线条的粗细

setcolor(YELLOW);

line(320 + x_minute, 240 - y_minute, 320 - x_minute / 5, 240 + y_minute/5);

//绘制时针

setlinestyle(PS_SOLID, 7); //PS_SOILD 实线 2像素 线条的粗细

setcolor(GREEN);

line(320 + x_hour, 240 - y_hour, 320 - x_hour / 5, 240 + y_hour/5);

}


最终的效果图:

注意一下!!!需要安装图形库。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

jinguangdi 发表于 2016-12-8 15:35
图裂啦,估计被楼主吃了
52pojie123 发表于 2016-12-8 15:42 来自手机
 楼主| 余辉 发表于 2016-12-8 15:43
魔术使nqy 发表于 2016-12-8 17:40 来自手机
想不到用C写一个那么普通的软件代码量却那么大了
莫名堂 发表于 2016-12-8 17:47
想不到用C写一个那么普通的软件代码量却那么大了来自: Android客户端
uatlaosiji 发表于 2016-12-8 19:20
graphics.h   turbo c 吗?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-23 13:30

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表