7 tclock - analog/digital clock for curses.
8 If it gives you joy, then
10 (b) you need to get out more :-)
12 This program is copyright Howard Jones, September 1994
13 (ha.jones@ic.ac.uk). It may be freely distributed as
14 long as this copyright message remains intact, and any
15 modifications are clearly marked as such. [In fact, if
16 you modify it, I wouldn't mind the modifications back,
17 especially if they add any nice features. A good one
18 would be a precalc table for the 60 hand positions, so
19 that the floating point stuff can be ditched. As I said,
20 it was a 20 hackup minute job.]
22 COMING SOON: tfishtank. Be the envy of your mac-owning
26 /* To compile: cc -o tclock tclock.c -lcurses -lm */
29 #define PI 3.141592654
32 #define sign(_x) (_x<0?-1:1)
35 #define ROUND(value) ((int)((value) + 0.5))
37 #define A2X(angle,radius) ROUND(ASPECT * radius * sin(angle))
38 #define A2Y(angle,radius) ROUND(radius * cos(angle))
42 plot(int x, int y, char col)
44 mvaddch(y, x, (chtype) col);
47 /* Draw a diagonal(arbitrary) line using Bresenham's alogrithm. */
49 dline(int pair, int from_x, int from_y, int x2, int y2, char ch)
58 attrset(COLOR_PAIR(pair));
108 char *argv[]GCC_UNUSED)
111 double mradius, hradius, mangle, hangle;
112 double sangle, sradius, hours;
121 int my_bg = COLOR_BLACK;
126 nodelay(stdscr, TRUE);
131 #ifdef NCURSES_VERSION
132 if (use_default_colors() == OK)
135 init_pair(1, COLOR_RED, my_bg);
136 init_pair(2, COLOR_MAGENTA, my_bg);
137 init_pair(3, COLOR_GREEN, my_bg);
140 keypad(stdscr, TRUE);
143 cx = (COLS - 1) / 2; /* 39 */
144 cy = LINES / 2; /* 12 */
145 ch = (cx > cy) ? cy : cx; /* usually cy */
146 mradius = (3 * cy) / 4; /* 9 */
147 hradius = cy / 2; /* 6 */
148 sradius = (2 * cy) / 3; /* 8 */
150 for (i = 0; i < 12; i++) {
151 sangle = (i + 1) * (2.0 * PI) / 12.0;
152 sradius = (5 * cy) / 6; /* 10 */
153 sdx = A2X(sangle, sradius);
154 sdy = A2Y(sangle, sradius);
155 sprintf(szChar, "%d", i + 1);
157 mvaddstr(cy - sdy, cx + sdx, szChar);
160 mvaddstr(0, 0, "ASCII Clock by Howard Jones (ha.jones@ic.ac.uk),1994");
169 hours = (t->tm_hour + (t->tm_min / 60.0));
173 mangle = ((t->tm_min) * (2 * PI) / 60.0);
174 mdx = A2X(mangle, mradius);
175 mdy = A2Y(mangle, mradius);
177 hangle = ((hours) * (2.0 * PI) / 12.0);
178 hdx = A2X(hangle, hradius);
179 hdy = A2Y(hangle, hradius);
181 sangle = ((t->tm_sec) * (2.0 * PI) / 60.0);
182 sdx = A2X(sangle, sradius);
183 sdy = A2Y(sangle, sradius);
185 dline(3, cx, cy, cx + mdx, cy - mdy, '#');
188 dline(2, cx, cy, cx + hdx, cy - hdy, '.');
192 attrset(COLOR_PAIR(1));
194 plot(cx + sdx, cy - sdy, 'O');
197 attrset(COLOR_PAIR(0));
199 mvaddstr(LINES - 2, 0, ctime(&tim));
201 if ((t->tm_sec % 5) == 0
202 && t->tm_sec != lastbeep) {
203 lastbeep = t->tm_sec;
207 if ((ch = getch()) != ERR) {
209 if (ch == KEY_RESIZE) {
217 plot(cx + sdx, cy - sdy, ' ');
218 dline(0, cx, cy, cx + hdx, cy - hdy, ' ');
219 dline(0, cx, cy, cx + mdx, cy - mdy, ' ');