Add missing includes, GCC 6.3 errored out
[aclock.git] / aclock-unix-aalib.c
1 /*
2  * aclock - ascii clock for UNIX Console
3  *
4  * Copyright (c) 2002 by Antoni Sawicki <as@tenoware.com>
5  * Version 1.8 (unix-aalib); Dublin, June 2002
6  *
7  * Compile: gcc -O2 aclock-unix-aalib.c -o aclock -laa -lm
8  *
9  */
10
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <math.h>
14 #include <time.h>
15 #include <aalib.h>
16
17 aa_context *context;
18
19 void cls(int width, int height) {
20         int x,y;
21         for(x=0; x<=width; x++)
22         for(y=0; y<=height; y++)
23                 aa_putpixel(context, x+1, y+1, 0);
24 }
25
26 void draw_circle(int hand_max, int sYcen, int sXcen, int FontHW){
27         int x,y,r;
28         int c;
29
30
31         for(r=0;r<60;r++){
32                 x=cos(r*M_PI/180*6)*hand_max*FontHW+sXcen;
33                 y=sin(r*M_PI/180*6)*hand_max+sYcen;
34                 switch (r) {
35                         case 0:
36                         case 5:
37                         case 10:
38                         case 15:
39                         case 20:
40                         case 25:
41                         case 30:
42                         case 35:
43                         case 40:
44                         case 45:
45                         case 50:
46                         case 55:
47                                 c=255;
48                                 break;
49                         default:
50                                 c=33;
51                                 break;
52                 }
53                 aa_putpixel(context, x+1, y+1, c);
54         }
55 }
56
57 void draw_hand(int minute, int hlenght, int c, int sXcen, int sYcen, int FontHW){
58         int x,y,n;
59         float r=(minute-15)*(M_PI/180)*6;
60
61         for(n=1; n<hlenght; n++){
62                 x=cos(r)*n*FontHW+sXcen;
63                 y=sin(r)*n+sYcen;
64                 aa_putpixel(context,x,y,c);
65         }
66 }
67
68
69 int main(void){
70         char INFO[]="Copyright (c) 2002 by Antek Sawicki <as@tenoware.com>\n"
71                     "Version 1.4; Dublin, Apr 2002\n";
72         char digital_time[15];
73         int FontHW = 2;
74         int sXmax, sYmax, smax, hand_max, sXcen, sYcen;
75         time_t t;
76         struct tm *ltime;
77
78         aa_recommendhidisplay("curses"); 
79         aa_recommendlowdisplay("curses"); 
80
81         context = aa_autoinit(&aa_defparams);
82
83         if(context == NULL) {
84                 fprintf(stderr,"Cannot initialize AA-lib. Giving up.\n");
85                 exit(1);
86         }
87
88         for(;;){
89                 time(&t);
90                 ltime=localtime(&t);
91                 sXmax = aa_scrwidth(context) * 2 - 4;
92                 sYmax = aa_scrheight(context) * 2 - 4;
93
94                 if(sXmax/2<=sYmax)
95                         smax=sXmax/2;
96                 else
97                         smax=sYmax;
98
99                 hand_max = (smax/2)-1;
100
101                 sXcen = sXmax/2;
102                 sYcen = sYmax/2;
103
104                 cls(sXmax,sYmax);
105                 draw_circle(hand_max, sYcen, sXcen, FontHW);
106
107
108                 draw_hand((ltime->tm_hour*5)+(ltime->tm_min/10), 2*hand_max/3, 255, sXcen, sYcen, FontHW);
109                 draw_hand(ltime->tm_min, hand_max-2, 100, sXcen, sYcen, FontHW);
110                 draw_hand(ltime->tm_sec, hand_max-2, 33, sXcen, sYcen, FontHW);
111
112                 aa_fastrender(context, 0, 0, sXmax, sYmax);
113
114                 aa_printf(context, sXmax/4-4, sYmax/8, AA_BOLD, ".:ACLOCK:.");
115                 aa_printf(context, sXmax/4-4, sYmax/2.5, AA_NORMAL, "[%02d:%02d:%02d]",
116                                         ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
117                 aa_flush(context);
118                 sleep(1);
119         }
120         return 0;
121 }