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