/* * aclock - ascii clock for UNIX Console - termcap port * * Copyright (c) 1994-2011 Antoni Sawicki * Version 2.1 (unix-termcap); Mountain View, Nov 2011 * * Compilation: cc aclock-unix-termcap.c -o aclock -ltermcap -lm * Built on: BeOS, Zeta, SkyOS, Haiku, Amiga-GG, UnixWare, Risc/OS * */ #include #include #include #include #include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif char *cm, *cl; void my_putchar(int c) { putchar(c); } void cls(void) { tputs(tgoto(cl, 0, 0), 1, (void*)my_putchar); } void draw_point(int x, int y, char c) { tputs(tgoto(cm, x, y), 1, (void*)my_putchar); putchar(c); } void draw_text(int x, int y, char *string) { tputs(tgoto(cm, x, y), 1, (void*)my_putchar); puts(string); } void draw_circle(int hand_max, int sYcen, int sXcen, int FontHW){ int x,y,r; char c; for(r=0;r<60;r++){ x=cos(r*M_PI/180*6)*hand_max*FontHW+sXcen; y=sin(r*M_PI/180*6)*hand_max+sYcen; switch (r) { case 0: case 5: case 10: case 15: case 20: case 25: case 30: case 35: case 40: case 45: case 50: case 55: c='o'; break; default: c='.'; break; } draw_point(x,y,c); } } void draw_hand(int minute, int hlenght, char c, int sXcen, int sYcen, int FontHW){ int x,y,n; float r=(minute-15)*(M_PI/180)*6; for(n=1; ntm_hour*5)+(ltime->tm_min/10), 2*hand_max/3, 'h', sXcen, sYcen, FontHW); draw_hand(ltime->tm_min, hand_max-2, 'm', sXcen, sYcen, FontHW); draw_hand(ltime->tm_sec, hand_max-1, '.', sXcen, sYcen, FontHW); draw_text(sXcen-5, sYmax/4, ".:ACLOCK:."); sprintf(digital_time, "[%02d:%02d:%02d]", ltime->tm_hour, ltime->tm_min, ltime->tm_sec); draw_text(sXcen-5, 4*sYmax/5, digital_time); fflush(stdout); sleep(1); draw_hand((ltime->tm_hour*5)+(ltime->tm_min/10), 2*hand_max/3, ' ', sXcen, sYcen, FontHW); draw_hand(ltime->tm_min, hand_max-2, ' ', sXcen, sYcen, FontHW); draw_hand(ltime->tm_sec, hand_max-1, ' ', sXcen, sYcen, FontHW); } return 0; }