-
Notifications
You must be signed in to change notification settings - Fork 14
/
aclock-plan9.c
129 lines (106 loc) · 2.75 KB
/
aclock-plan9.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
/*
* aclock - ascii clock - Plan 9 Rio port (updated)
*
* Copyright (c) 2002-2005 Antoni Sawicki <[email protected]>
* Version 1.8 (plan9-rio); Dublin, March 2005
*
*/
#include <u.h>
#include <stdio.h>
#include <libc.h>
#include <draw.h>
#include <cursor.h>
Image *white, *black, *blue;
Point size, pos;
void cls(void) {
draw(screen, screen->r, white, nil, pos);
}
void draw_point(int x, int y, char c) {
char str[2];
str[0]=c;
str[1]=0;
string(screen, addpt(screen->r.min, Pt(x*size.x, y*size.y)), black, ZP, display->defaultfont, str);
}
void draw_text(int x, int y, char *str) {
string(screen, addpt(screen->r.min, Pt(x*size.x, y*size.y)), blue, ZP, display->defaultfont, str);
}
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*PI/180*6)*hand_max*FontHW+sXcen;
y=sin(r*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)*(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);
}
}
int main(void){
char INFO[]="Copyright (c) 2002 by Antek Sawicki <[email protected]>\n"
"Version 1.8; Dublin, June 2002\n";
char digital_time[15];
int FontHW;
int kbd, mse;
int sXmax, sYmax, smax, hand_max, sXcen, sYcen;
long t;
struct Tm *ltime;
initdraw(0,0,"aclock");
white = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DWhite);
black = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlack);
blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlue);
kbd=open("/dev/consctl", OREAD);
mse=open("/dev/mouse", OREAD);
size=stringsize(display->defaultfont, " ");
FontHW=size.y/size.x;
while(1){
time(&t);
ltime=localtime(t);
getwindow(display, Refnone);
sXmax = (screen->r.max.x-screen->r.min.x)/size.x;
sYmax = (screen->r.max.y-screen->r.min.y)/size.y;
if((sXmax+2)/2<sYmax)
smax=(sXmax/2)-2;
else
smax=sYmax;
hand_max = (smax/2)-1;
sXcen = sXmax/2;
sYcen = sYmax/2;
cls();
draw_circle(hand_max, sYcen, sXcen, FontHW);
draw_hand((ltime->hour*5)+(ltime->min/10), 2*hand_max/3, 'h', sXcen, sYcen, FontHW);
draw_hand(ltime->min, hand_max-2, 'm', sXcen, sYcen, FontHW);
draw_hand(ltime->sec, hand_max-1, '.', sXcen, sYcen, FontHW);
draw_text(sXcen-5, sYmax/4, ".:ACLOCK:.");
sprintf(digital_time, "[%02d:%02d:%02d]", ltime->hour, ltime->min, ltime->sec);
draw_text(sXcen-5, 4*sYmax/5, digital_time);
flushimage(display, 1);
sleep(1000);
}
return 0;
}