Anda di halaman 1dari 7

#include <stdio.

h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <dos.h>

void innerborder(int start_horiz, int start_vert, int end_horiz, int end_vert);


void shadedborder(int start_horiz, int start_vert, int end_horiz, int end_vert);
void outerborder(int start_horiz, int start_vert, int end_horiz, int end_vert);
void Init(void);

//Global Vars
int c, h, w, i;
struct text_info t_info;

int main()
{
struct tm full_m;
time_t fm_dbase,now;
register double span;
double phase_secs = 2551442.8;
double half_phase = phase_secs /2L;
double days_slfm,days_tnfm,days_tnnm,days_slnm;
double secs_slfm, secs_tnfm, value;
long whole_num;
int phase;

Init();

start:
clrscr();

/* time from 1985 Yrbook of Astronomy, p 73 (GMT) */

full_m.tm_sec = 0;
full_m.tm_min = 16; /*24*/
full_m.tm_hour = 2; /*2*/
full_m.tm_mday = 7; /*04*/ /*day of month!*/
full_m.tm_mon = 0; /*5*/ /* 0=JAN */
full_m.tm_year = 85; /*93*/
fm_dbase = mktime(&full_m); /*mktime() Convt tm struct to time_t value.*/

now = time(NULL);
span = difftime(now, fm_dbase);
value = span / phase_secs;
whole_num = value; /* trick! Assign float value to integer. (kill ext)*/
value = whole_num * phase_secs; /* value = all full phases past in secs*/
secs_slfm = span - value;
secs_tnfm = phase_secs - secs_slfm;
days_slfm = secs_slfm /(60L*60L*24L);
days_tnfm = secs_tnfm /(60L*60L*24L);
if(secs_tnfm < half_phase)
days_tnnm = (secs_tnfm + half_phase) /(60L*60L*24L);
else{
days_tnnm = (secs_tnfm - half_phase) /(60L*60L*24L);
}
if(secs_slfm < half_phase)
days_slnm = (secs_slfm + half_phase)/(60L*60L*24L);
else{
days_slnm = (secs_slfm - half_phase)/(60L*60L*24L);
}

if(secs_slfm < phase_secs /4L)


phase = 3;
else{
if(secs_slfm < phase_secs /2L)
phase = 4;
else{
if(secs_slfm < (phase_secs /4L)*3L)
phase = 1;
else{
if(secs_slfm < phase_secs)
phase = 2;
}}}

/* small main box */


window(35, 11, 45, 14);
textattr(BLUE *16|WHITE);
clrscr();
textattr(BLACK *16|LIGHTBLUE);
innerborder(35, 11, 45, 14);

/* medium-small main box */


window(30, 9, 50, 16);
textattr(BLUE *16|WHITE);
clrscr();
textattr(BLACK *16|LIGHTBLUE);
innerborder(30, 9, 50, 16);

/* medium main box */


window(25, 8, 55, 17);
textattr(BLUE *16|WHITE);
clrscr();
textattr(BLACK *16|LIGHTBLUE);
innerborder(25, 8, 55, 17);

/* full size main box */

window(20, 7, 60, 18);


textattr(BLUE *16|WHITE);
clrscr();
window(19, 6, 61, 19);
textattr(BLACK *16|LIGHTBLUE);
innerborder(19, 6, 61, 18);
shadedborder(19, 6, 61, 18);
textattr(BLACK *16|LIGHTCYAN);
outerborder(19, 6, 61, 18);
textattr(BLUE *16|LIGHTCYAN);
gotoxy(9, 5);
cputs("A lunar month is 29.53 days");

textattr(BLUE *16|WHITE);
gotoxy(6, 6);
cprintf("%.1f days until next new moon",days_tnnm);
gotoxy(6, 8);
cprintf("%.1f days until next full moon",days_tnfm);
gotoxy(6, 7);
cprintf("%.1f days since last new moon",days_slnm);
gotoxy(6, 9);
cprintf("%.1f days since last full moon",days_slfm);

window(1, 20, 79, 21);


textattr(BLACK *16|GREEN);
gotoxy(17,1);
if(phase == 1)
cprintf("The moon is in it's %dst Quarter, and is waxing.",phase);
if(phase == 2)
cprintf("The moon is in it's %dnd Quarter, and is waxing.",phase);
if(phase == 3)
cprintf("The moon is in it's %drd Quarter, and is waning.",phase);
if(phase == 4)
cprintf("The moon is in it's %dth Quarter, and is waning.",phase);

window(1, 22, 79, 23);


textattr(BLACK *16|DARKGRAY);
gotoxy(12,1);
cputs("The LUNAR PHASE and DATA Utility, (c) 1993 by Gene_Frequency");

window(1, 4, 80, 5);


textattr(BLACK *16|LIGHTCYAN);
while (1) // Forever
{
time_t timer; // 'time_t' is #defined to be 'long'.
struct tm *timeptr;
char long wrkstr[160];
int sec;

while (!kbhit())
{
time(&timer); // Store elapsed seconds in timer.
timeptr = localtime(&timer); // localtime / gmtime

window(1, 4, 80, 5);


textattr(BLACK *16|LIGHTCYAN);
gotoxy(11,1);
strftime(wrkstr,sizeof(wrkstr),
"LUNAR PHASE DATA FOR: %a, %d%b%y, %H:%M:%S (%I:%M:%S %p).",timeptr)
;cputs(strupr(wrkstr));

sec = timeptr->tm_sec;
if(sec == 0) {
delay(999);

goto start;
}

}
if ( getch() < 257 )
break;
}

clrscr();
_setcursortype(_NORMALCURSOR);
return(0);
}

void innerborder(int start_horiz, int start_vert, int end_horiz, int end_vert)


{
/* top line */

register int i;
gotoxy(2, 2);
for(i=1; i <= end_horiz - start_horiz-2; i++)
putch(178);

/* bottom line */
gotoxy(2, end_vert - start_vert-1);
for(i=1; i <= end_horiz - start_horiz-2; i++)
putch(178);
for(i=2; i <= end_vert - start_vert-1; i++)
{
gotoxy(2, i);
putch(178);
gotoxy(end_horiz - start_horiz - 1, i);
putch(178);
}
}

void shadedborder(int start_horiz, int start_vert, int end_horiz, int end_vert)


{
/* top line */
register int i;

gotoxy(4, 3);
for(i=1; i <= end_horiz - start_horiz - 5; i++)
putch(176);

/* bottom line */

gotoxy(2, end_vert-start_vert);
for(i=2; i <= end_horiz - start_horiz; i++)
putch(176);

for(i=3; i <= 10; i++) {


gotoxy(3, i);
putch(178);
}
for(i=2; i < 12; i++) {
gotoxy(end_horiz - start_horiz, i);
putch(178);
}
}

void outerborder(int start_horiz, int start_vert, int end_horiz, int end_vert)


{
/* top line */
register int i;
gotoxy(2, 1);
for(i=2; i <= end_horiz - start_horiz; i++)
putch(205);

/* bottom line */

gotoxy(2, end_vert - start_vert + 1);


for(i=2; i <= end_horiz - start_horiz; i++)
putch(205);

for(i=2; i <= end_vert - start_vert; i++) {


gotoxy(1, i);
putch(186);

gotoxy(end_horiz - start_horiz + 1, i);


putch(186);
}
/* "do corners" */

gotoxy(1, 1);
putch(201);

gotoxy(end_horiz - start_horiz + 1, 1);


putch(187);

gotoxy(1, end_vert - start_vert + 1);


putch(200);

gotoxy(end_horiz - start_horiz + 1, end_vert - start_vert + 1);


putch(188);

void Init(void)
{
_setcursortype(_NOCURSOR);
clrscr();
gettextinfo(&t_info);
w = t_info.screenwidth;
h = t_info.screenheight;
}

Anda mungkin juga menyukai