8 tclock - analog/digital clock for curses.
9 If it gives you joy, then
11 (b) you need to get out more :-)
13 This program is copyright Howard Jones, September 1994
14 (ha.jones@ic.ac.uk). It may be freely distributed as
15 long as this copyright message remains intact, and any
16 modifications are clearly marked as such. [In fact, if
17 you modify it, I wouldn't mind the modifications back,
18 especially if they add any nice features. A good one
19 would be a precalc table for the 60 hand positions, so
20 that the floating point stuff can be ditched. As I said,
21 it was a 20 hackup minute job.]
23 COMING SOON: tfishtank. Be the envy of your mac-owning
27 /* To compile: cc -o tclock tclock.c -lcurses -lm */
30 #define PI 3.141592654
33 #define sign(_x) (_x<0?-1:1)
36 #define ROUND(value) ((int)((value) + 0.5))
38 #define A2X(angle,radius) ROUND(ASPECT * radius * sin(angle))
39 #define A2Y(angle,radius) ROUND(radius * cos(angle))
43 plot(int x,int y,char col)
45 mvaddch(y,x,(chtype)col);
49 /* Draw a diagonal(arbitrary) line using Bresenham's alogrithm. */
51 dline(int from_x, int from_y, int x2, int y2, char ch)
112 char *argv[] GCC_UNUSED)
115 double mradius, hradius, mangle, hangle;
116 double sangle, sradius, hours;
135 sangle=(i+1)*(2.0*PI)/12.0;
137 sdx = A2X(sangle, sradius);
138 sdy = A2Y(sangle, sradius);
139 sprintf(szChar,"%d",i+1);
141 mvaddstr((int)(cy-sdy),(int)(cx+sdx),szChar);
144 mvaddstr(0,0,"ASCII Clock by Howard Jones (ha.jones@ic.ac.uk),1994");
154 hours = (t->tm_hour + (t->tm_min/60.0));
155 if(hours>12.0) hours -= 12.0;
157 mangle = ((t->tm_min) * (2 * PI)/60.0);
158 mdx = A2X(mangle, mradius);
159 mdy = A2Y(mangle, mradius);
161 hangle = ((hours) * (2.0 * PI)/12.0);
162 hdx = A2X(hangle, hradius);
163 hdy = A2Y(hangle, hradius);
165 sangle = ((t->tm_sec) * (2.0 * PI)/60.0);
166 sdx = A2X(sangle, sradius);
167 sdy = A2Y(sangle, sradius);
169 plot(cx+sdx,cy-sdy,'O');
170 dline(cx,cy,cx+hdx,cy-hdy,'.');
171 dline(cx,cy,cx+mdx,cy-mdy,'#');
173 mvaddstr(23,0,ctime(&tim));
175 if ((t->tm_sec % 5) == 0) beep();
177 plot(cx+sdx,cy-sdy,' ');
178 dline(cx,cy,cx+hdx,cy-hdy,' ');
179 dline(cx,cy,cx+mdx,cy-mdy,' ');