📄 clocktst.c
字号:
#include "gui.h"
#include "timer.h"
#include <math.h>
int midx, midy;
static unsigned char h=0, m=0, s=0;
#define pi 3.1415926
void Clk_Dp( unsigned char a, unsigned char b, unsigned char c )
{
unsigned short x, y;
x = a * cos(b*c*pi/180.0-pi/2) + midx;
y = a * sin(b*c*pi/180.0-pi/2) + midy;
GUI_DrawLine(midx,midy,x,y);
}
void Clk_ShowTime( TIME *t )
{
GUI_COLOR bak;
bak = GUI_GetColor();
GUI_SetColor( GUI_RED );
GUI_GotoXY( 10, 10 );
// GUI_DispString("Current time is: ");
GUI_DispDec( t->hour, 2 );
GUI_DispString(":");
GUI_DispDec( t->minute, 2 );
GUI_DispString(":");
GUI_DispDec( t->second, 2 );
GUI_SetColor( bak );
}
void Clk_Init( void )
{
int i, x1, x2, y1, y2, l;
int radius = 100;
GUI_SetBkColor( GUI_BLACK ); /*背景顔色為 BLUE*/
GUI_Clear();
GUI_SetColor( GUI_GREEN ); /*設置裏面circle的顔色*/
GUI_DrawCircle( midx, midy, radius );
GUI_SetColor( GUI_MAGENTA ); /*设置外面圆的颜色*/
GUI_DrawCircle( midx, midy, radius+5 );
GUI_SetColor( GUI_CYAN ); /*设置圆心的颜色*/
GUI_DrawCircle( midx, midy, 2 );
for( i=0; i<60; i++ ) /* Draw刻度盘 */
{
if( i%5 == 0 )
l = 15;
else
l = 5;
x1 = 100*cos(i*6*pi/180) + midx;
y1 = 100*sin(i*6*pi/180) + midy;
x2 = (100-l)*cos(i*6*pi/180) + midx;
y2 = (100-l)*sin(i*6*pi/180) + midy;
GUI_DrawLine( x1, y1, x2, y2 );
}
}
void Clk_DrawSec( TIME *t )
{
GUI_SetColor( GUI_BLACK ); //clear pre sec hand
Clk_Dp( 90, s, 6 );
GUI_SetColor( GUI_RED );
s = t->second;
Clk_Dp( 90, s, 6 );
}
void Ckl_DrawMin( TIME *t )
{
GUI_SetColor( GUI_BLACK );
Clk_Dp( 75, m, 6 );
GUI_SetColor( GUI_YELLOW );
m = t->minute;
Clk_Dp( 75, m, 6 );
}
void ClockTst( void )
{
float x, y;
TIME t;
midx = 320 / 2; /*得到圆心坐标 */
midy = 240 / 2;
Clk_Init();
DgGetTime( &t ); /*get the time*/
h = t.hour;
m = t.minute;
s = t.second;
Clk_ShowTime( &t );
/*draw the hour_hand*/
GUI_SetColor( GUI_LIGHTGRAY );
Clk_Dp( 60, (h+(float)m/60), 30 );/*这一行是很关键的。有了这一行时针就可以随着 */
/*分针的移动而随时移动了,从而改变了原来的只有*/
/*到整点时针才能变动的局限 */
/*draw the min_hand*/
GUI_SetColor( GUI_YELLOW );
Clk_Dp( 75, m, 6 );
/*draw the sec_hand*/
GUI_SetColor( GUI_RED );
Clk_Dp( 90, s, 6 );
while( 1 )
{
while( t.second == s )
DgGetTime( &t );
Clk_ShowTime( &t );
Clk_DrawSec( &t );
if( t.minute != m )
{
Ckl_DrawMin( &t );
}
if( m == s-1 )
{
GUI_SetColor( GUI_YELLOW );
Clk_Dp( 75, m, 6 );
}
GUI_SetColor( GUI_BLACK );
Clk_Dp( 60, h+(float)m/60.0, 30 );
GUI_SetColor( GUI_LIGHTGRAY );
h = (float)t.hour;
Clk_Dp( 60, h+(float)m/60.0, 30 );
// if( t.hour != (int)h )
// {
// GUI_SetColor( GUI_LIGHTGRAY );
// Clk_Dp( 60, h, 30 );
// h = t.hour;
// Clk_Dp( 60, h, 30 );
// }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -