]> arthur.barton.de Git - aclock.git/blob - aclock-unix-curses.c
Add missing includes, GCC 6.3 errored out
[aclock.git] / aclock-unix-curses.c
1 /*
2  * aclock - ascii clock for UNIX Console
3  *
4  * Copyright (c) 2002 Antoni Sawicki <as@tenoware.com>
5  * Version 2.3 (unix-curses); Mountain View, July 2013
6  *
7  * Compilation: cc aclock-unix-curses.c -o aclock -lcurses -lm
8  *
9  */
10
11 #include <unistd.h>
12 #include <curses.h>
13 #include <math.h>
14 #include <time.h>
15
16 #ifndef M_PI
17 #define M_PI 3.14159265358979323846
18 #endif
19
20 #define FontWH_Ratio 2  
21
22 void draw_circle(int hand_max, int sYcen, int sXcen){
23     int x,y,r;
24     char c;
25
26     for(r=0;r<60;r++){
27         x=cos(r*M_PI/180*6)*hand_max*FontWH_Ratio+sXcen;
28         y=sin(r*M_PI/180*6)*hand_max+sYcen;
29         switch (r) {
30             case 0:
31             case 5:
32             case 10:
33             case 15:
34             case 20:
35             case 25:
36             case 30:
37             case 35:
38             case 40:
39             case 45:
40             case 50:
41             case 55:
42                 c='o';
43                 break;
44             default:
45                 c='.';
46                 break;
47         }
48         mvaddch(y,x,c);
49     }
50 }
51
52 void draw_hand(int minute, int hlenght, char c, int sXcen, int sYcen){
53     int x,y,n;
54     float r=(minute-15)*(M_PI/180)*6;
55
56     for(n=1; n<hlenght; n++){
57         x=cos(r)*n*FontWH_Ratio+sXcen;
58         y=sin(r)*n+sYcen;
59         mvaddch(y,x,c);
60     }
61 }
62
63
64 int main(void){
65     char INFO[]="Copyright (c) 1994-2013 Antoni Sawicki <as@tenoware.com>\n"
66                 "Version 2.3 (unix-curses); Mountain View, July 2013\n";
67     char digital_time[15];
68     int sXmax, sYmax, smax, hand_max, sXcen, sYcen;
69     time_t t;
70     struct tm *ltime;
71
72     sXmax=sYmax=hand_max=sXcen=sYcen=0;
73     initscr();
74
75     while(1){
76         time(&t);
77         ltime=localtime(&t);
78         sXmax = COLS;
79         sYmax = LINES;
80
81         if(sXmax/FontWH_Ratio<=sYmax)
82             smax=sXmax/FontWH_Ratio;
83         else
84             smax=sYmax;
85
86         hand_max = (smax/2)-1;
87
88         sXcen = sXmax/2;
89         sYcen = sYmax/2;
90
91         erase();
92         draw_circle(hand_max, sYcen, sXcen);
93
94         draw_hand((ltime->tm_hour*5)+(ltime->tm_min/10), 2*hand_max/3, 'h', sXcen, sYcen);
95         draw_hand(ltime->tm_min, hand_max-2, 'm', sXcen, sYcen);
96         draw_hand(ltime->tm_sec, hand_max-1, '.', sXcen, sYcen);
97
98         mvaddstr(sYcen-(3*hand_max/5), sXcen-5, ".:ACLOCK:.");
99         mvprintw(sYcen+(3*hand_max/5), sXcen-5, "[%02d:%02d:%02d]", ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
100
101         refresh();
102         sleep(1);
103     }
104     endwin();
105     return 0;
106 }