C Language Clock Source Procedure (can be used according to the mechanical table, but also display time and date by electronic w

xiaoxiao2021-03-06  101

*********************************************************** ************

* C language clock source program

* Nanyang Institute of Technology Computer Department 01612 Ban Dapeng course design work

* Operating environment: TC2.0

* Email: ypsky@mail2.nyist.net

*********************************************************** ***********

#include "graphics.h"

#define pi 3.1416

#include "math.h"

#include "dos.h"

Main ()

{

INT X0 = 320, Y0 = 240, R0 = 150;

Void init_sceen ();

Void sec ();

INIT_SCEEN (X0, Y0, R0);

sec ();

Closegraph ();

}

Void init_sceen (int X0, int y0, int R0) / ******************************************* ******* /

{

Int i, x, y, graphdriver, graphmode;

Char s [10];

Float alpha, A0 = 90;

Graphdriver = detect;

INITGRAPH (& graphdriver, & graphmode, "");

Setbkcolor (3);

SetColor (2);

Circle (X0, Y0, R0);

Circle (X0, Y0, R0 30);

SetFillStyle (Solid_Fill, 10);

FLOODFILL (X0-R0-10, Y0, 2);

/ * please input the time * /

For (i = 12; i> = 1; I -)

{

Alpha = (A0 30 * (11-I) * PI / 180);

X = x0 cos (alpha) * r0-16;

Y = Y0-sin (alpha) * r0;

Sprintf (s, "% 2d", i);

SetColor (4);

SetTextStyle (0,0,2);

OutTextxy (X, Y, S);

}

/ * Input Second * /

For (i = 60; I> = 1; I -)

{

Alpha = (A0 6 * (60-I) * PI / 180);

X = x0 cos (alpha) * (r0-20);

Y = Y0-sin (alpha) * (R0-20);

SetColor (14);

IF (i% 5 == 0)

Circle (x, y, 5);

Else Circle (X, Y, 2);

FLOODFILL (X, Y, 14);

}

SetLinesTyle (0,0,3);

}

Void SEC (void) / ************************************************************* ********************* /

{

INT X, Y, I, J, K, XJ, YJ, XK, YK, XI, Yi, X0 = 320, Y0 = 240, R0 = 150;

Union regs r;

Unsigned char * shijie = "";

Unsigned char * DAA = ""

Struct Time Tim;

Struct DAT;

Float alphai, alphak, alphaj, A0 = 90;

Xi = X0; yi = Y0; xj = x0; yj = Y0; xk = x0; yk = Y0;

DO

{

/ * INTPUT the time * / x = 38; y = 12;

GetTime (& TIM);

Sprintf (shijie, "% 02d:% 02d:% 02d", Tim.Ti_Hour, Tim.Ti_MIN, TIM.TI_SEC);

SetFillStyle (Solid_Fill, 0);

Bar (245, 190, 375, 210);

SetColor (15);

Outtextxy (245, 190, shijie);

/ * Input the date * / / **************************************************** *********** /

GetDate (& DAT);

Sprintf (DAA, "% 02D -% 02D -% 02D", DAT.DA_YEAR, DAT.DA_MON, DAT.DA_DAY);

/ * setFillStyle (Solid_Fill, 3); * /

BAR (225, 290, 395, 310);

SetColor (red);

OutTextxy (225, 290, DAA);

x = 190; y = 430;

SetColor (red);

Outtextxy (X-26, Y, "Designed by Guoliuta0");

SetColor (Lightred);

Outtextxy (x 76, y0 20, "nba game");

SetLinesTyle (0,0,3);

K = TIM.TI_HOUR;

J = TIM.TI_MIN;

I = TIM.TI_SEC;

Alphak = (A0 30 * (12-K) -J * 5 / 60. * 6) * PI / 180;

Alphaj = (A0-6 * J) * pi / 180;

/ * Write Second Hand * /

Alphai = (A0 6 * (60-I)) * pi / 180;

X = X0 COS (alphai) * (R0-32);

Y = Y0-sin (alphai) * (R0-32);

SetColor (Black);

LINE (X0, Y0, Xi, Yi);

SetColor (YELLOW);

LINE (X0, Y0, X, Y);

Xi = x;

Yi = Y;

/ * Write Minute Hand * /

X = x0 cos (alphaj) * (r0-60);

Y = Y0-sin (alphaj) * (r0-60);

SetColor (Black);

LINE (X0, Y0, XJ, YJ);

SetColor (Blue);

LINE (X0, Y0, X, Y);

xj = x;

Yj = Y;

/ * WRITE HOUR HAND * /

X = x0 cos (alphak) * (R0-99);

Y = Y0-sin (alphak) * (R0-99);

SetColor (Black);

LINE (X0, Y0, XK, YK);

SetColor (red);

LINE (X0, Y0, X, Y);

XK = x;

YK = Y;

DELAY (10000);

}

While (! kbhit ());

}

转载请注明原文地址:https://www.9cbs.com/read-123970.html

New Post(0)