时钟指针角度c语言,带指针的【七彩时钟】(C语言)

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

/*=================================================

编译环境: VC6.0

头文件: graphics.h 可以在http:www.easyx.cn下到

名称: 时钟

BY:huazai

=================================================*/

#include

#include

#include

const double Radian = 0.104719; // 走一个刻度的弧度

const int R3 = 150;

const int R2 = R3 - 3;

const int R1 = R2 - 8;

const int FontSize = 25;

const int R4 = R3 + FontSize +4;

const int RS = R1 - 5;

const int RM = RS - 30;

const int RH = RM - 40;

const int OriginX = 300;

const int OriginY = 200;

int colors = RED;

int count = 0;

void DrawCircleAndScale (void);

void ShowText (void);

void ShowTime (void);

void ShowSecondHand (tm tms);

void ShowMinuteHand (tm tms);

void ShowHourHand (tm tms);

int main()

{

using namespace std;

initgraph(640, 480);// 初始化绘图窗口

setcolor(YELLOW);

setorigin(OriginX,OriginY);

DrawCircleAndScale();

ShowText();

ShowTime();

closegraph();

return 0;

}

void DrawCircleAndScale (void)

{

// 设置线条的粗度

setlinestyle (PS_SOLID, NULL, 2);

circle (0, 0, R3);// 画内圆

int i;

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

{

int tempx;

int tempy;

if (i%5 == 0)

{

tempx = int(R1*cos(Radian*i));

tempy = int(R1*sin(Radian*i));

}

else

{

tempx = int(R2*cos(Radian*i));

tempy = int(R2*sin(Radian*i));

}

line (

int(tempx),

int(tempy),

int(R3*cos(Radian*i)),

int(R3*sin(Radian*i))

);

}

circle (0, 0, R4);//画外圆

setlinestyle (PS_SOLID, NULL, 1);// 还原线条粗度

}

void ShowText (void)

{

setfont(FontSize, 0, "Arial");

RECT r1 = {-R3, -(2*R3+FontSize), R3, 0};

drawtext("12", &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

RECT r2 = {0, -R3, 2*R3+FontSize, R3};

drawtext("3", &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

RECT r3 = {-R3, 0, R3, 2*R3+FontSize+4};

drawtext("6", &r3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

RECT r4 = {-(2*R3+FontSize), -R3, 0, R3};

drawtext("9", &r4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

setfont(FontSize*2, 0, "宋体");

RECT r5 = {-R4*2, 0, R4*2, 2*R3+FontSize*5};

drawtext("日月经天 江河行地", &r5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

setfont(FontSize, 0, "宋体");

RECT r6 = {0, 0, R4*3, 2*R3+FontSize*8};

drawtext("BY:huazai", &r6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

}

void ShowTime (void)

{

while(1)

{

DrawCircleAndScale();

ShowText();

time_t t = time(0);

tm ti = *localtime(&t);

ShowSecondHand(ti);

ShowMinuteHand(ti);

ShowHourHand(ti);

Sleep(1000);

cleardevice();

switch (count%16)

{

case 0 : colors = BLUE; break;

case 1 : colors = GREEN; break;

case 2 : colors = CYAN; break;

case 3 : colors = RED; break;

case 4 : colors = MAGENTA; break;

case 5 : colors = BROWN; break;

case 6 : colors = LIGHTGRAY; break;

case 7 : colors = DARKGRAY; break;

case 8 : colors = LIGHTBLUE; break;

case 9 : colors = LIGHTGREEN; break;

case 10 : colors = LIGHTCYAN; break;

case 11 : colors = LIGHTRED; break;

case 12 : colors = LIGHTMAGENTA; break;

case 13 : colors = YELLOW; break;

case 14 : colors = WHITE; break;

case 15 : colors = BROWN; break;

case 16 : colors = GREEN; break;

}

count++;

}

}

void ShowSecondHand (tm tms)

{

line (

0,

0,

RS*cos(Radian*tms.tm_sec - Radian*15),

RS*sin(Radian*tms.tm_sec - Radian*15)

);

}

void ShowMinuteHand (tm tms)

{

setlinestyle (PS_SOLID, NULL, 4);

setcolor(GREEN);

line (

0,

0,

RM*cos(Radian*tms.tm_min - Radian*15),

RM*sin(Radian*tms.tm_min - Radian*15)

);

setcolor(colors);

}

void ShowHourHand (tm tms)

{

setlinestyle (PS_SOLID, NULL, 8);

setcolor(BLUE);

line (

0,

0,

RH*cos(Radian*5*tms.tm_hour - Radian*15 + Radian*tms.tm_min/15),

RH*sin(Radian*5*tms.tm_hour - Radian*15 + Radian*tms.tm_min/15)

);

setcolor(colors);

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值