-
Notifications
You must be signed in to change notification settings - Fork 14
/
aclock-win32.c
152 lines (118 loc) · 3.59 KB
/
aclock-win32.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* aclock - ascii clock for Windows Console
*
* Copyright (c) 1994-2010 by Antoni Sawicki <[email protected]>
* Version 2.2 (win32); Mountain View, November 2010
*
* Compile: cl aclock-win32.c
*
*/
#include <windows.h>
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
HANDLE hConsole;
CONSOLE_SCREEN_BUFFER_INFO console_info;
void cls(void){
COORD home;
DWORD size;
int wchars;
home.X = 0;
home.Y = 0;
size = console_info.dwSize.X * console_info.dwSize.Y;
FillConsoleOutputCharacter(hConsole, ' ', size, home, &wchars);
}
void draw_point(int x, int y, char p){
COORD cursor_position;
int wchars;
cursor_position.X = x;
cursor_position.Y = y;
SetConsoleCursorPosition(hConsole, cursor_position);
WriteConsole(hConsole, &p, 1, &wchars, NULL);
}
void draw_circle(int hand_max, int sYcen, int sXcen, int FontHW, int hour){
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; n<hlenght; n++){
x=cos(r)*n*FontHW+sXcen;
y=sin(r)*n+sYcen;
draw_point(x,y,c);
}
}
void draw_text(char p[], int x, int y){
COORD cursor_position;
int wchars;
cursor_position.X = x;
cursor_position.Y = y;
SetConsoleCursorPosition(hConsole, cursor_position);
WriteConsole(hConsole, p, strlen(p), &wchars, NULL);
}
int main(void){
char INFO[]="Written by Antoni Sawicki <[email protected]>"
"Version 2.2; Mountain View, Nov 2010\n";
char digital_time[15];
int FontHW = 2;
int sXmax, sYmax, smax, hand_max, sXcen, sYcen, wchars;
CONSOLE_CURSOR_INFO cursor_info;
SYSTEMTIME local_time;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTitle("aclock 2.2 (Win32)");
GetConsoleScreenBufferInfo(hConsole, &console_info);
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 1;
SetConsoleCursorInfo(hConsole, &cursor_info);
sXmax=sYmax=hand_max=sXcen=sYcen=0;
while(1){
GetConsoleScreenBufferInfo(hConsole, &console_info);
sXmax = console_info.srWindow.Right;
sYmax = console_info.srWindow.Bottom-console_info.srWindow.Top;
if(sXmax/FontHW<=sYmax)
smax=sXmax/FontHW;
else
smax=sYmax;
hand_max = (smax/2)-1;
sXcen = sXmax/2;
sYcen = sYmax/2;
GetLocalTime(&local_time);
cls();
draw_circle(hand_max, sYcen, sXcen, FontHW, local_time.wHour);
draw_hand(local_time.wHour*5+local_time.wMinute/10, 2*hand_max/3, 'h', sXcen, sYcen, FontHW);
draw_hand(local_time.wMinute, hand_max-2, 'm', sXcen, sYcen, FontHW);
draw_hand(local_time.wSecond, hand_max-1, '.', sXcen, sYcen, FontHW);
draw_text(".:ACLOCK:.", sXcen-5,sYcen-3*hand_max/5);
sprintf(digital_time, "[%02d:%02d:%02d]", local_time.wHour, local_time.wMinute, local_time.wSecond);
draw_text(digital_time, sXcen-5, sYcen+3*hand_max/5);
Sleep(1000);
}
return 0;
}