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)
37 plot(int x,int y,char col)
39 mvaddch(y,x,(chtype)col);
43 /* Draw a diagonal(arbitrary) line using Bresenham's alogrithm. */
45 dline(int from_x, int from_y, int x2, int y2, char ch)
106 char *argv[] GCC_UNUSED)
109 double mradius, hradius, mangle, hangle;
110 double sangle, sradius, hours;
129 sangle=(i+1)*(2.0*PI)/12.0;
131 sdx=2.0*sradius*sin(sangle);
132 sdy=sradius*cos(sangle);
133 sprintf(szChar,"%d",i+1);
135 mvaddstr((int)(cy-sdy),(int)(cx+sdx),szChar);
138 mvaddstr(0,0,"ASCII Clock by Howard Jones (ha.jones@ic.ac.uk),1994");
148 hours=(t->tm_hour + (t->tm_min/60.0));
149 if(hours>12.0) hours-=12.0;
151 mangle=(t->tm_min)*(2*PI)/60.0;
152 mdx=2.0*mradius*sin(mangle);
153 mdy=mradius*cos(mangle);
155 hangle=(hours)*(2.0*PI)/12.0;
156 hdx=2.0*hradius*sin(hangle);
157 hdy=hradius*cos(hangle);
159 sangle=(t->tm_sec%60)*(2.0*PI)/60.0;
160 sdx=2.0*sradius*sin(sangle);
161 sdy=sradius*cos(sangle);
163 plot(cx+sdx,cy-sdy,'O');
164 dline(cx,cy,cx+hdx,cy-hdy,'.');
165 dline(cx,cy,cx+mdx,cy-mdy,'#');
167 mvaddstr(23,0,ctime(&tim));
170 plot(cx+sdx,cy-sdy,' ');
171 dline(cx,cy,cx+hdx,cy-hdy,' ');
172 dline(cx,cy,cx+mdx,cy-mdy,' ');