3 * gcc -lm aclox.c -o aclox; ./aclox
5 * CFLAGS='-lm' make aclox; ./aclox
15 #include <sys/ioctl.h>
18 #define HOUR_NUMBERS 1
19 #define HI_PRECISION 1
22 #define SMOOTH_MOTION 1
26 #define max(a,b) ((a)>=(b)?(a):(b))
27 #define min(a,b) ((a)<=(b)?(a):(b))
28 #define PI 3.141592654
29 #define deg2rad(a) (((a)/180)*PI)
30 //phi = angle, r = length
31 #define polar2x(phi, r) ((r) * cos(deg2rad(phi)))
32 #define polar2y(phi, r) ((r) * sin(deg2rad(phi)))
33 #define cls() printf("\033[2J")
34 #define top() printf("\033[0;0H")
36 int llines
= -1, lcols
= -1;
37 void render_clock(double h
, double m
, double s
) {
39 char color_empty
= ' ';
40 char color_center
= '+';
41 char color_number
= '#';
47 //convert digital time to "analog" time (enables smooth motion)
53 //get size of terminal
57 p = popen("stty size", "r");
58 fscanf(p, "%d %d", &lines, &cols);
61 if ((ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
) == -1 &&
62 ioctl(STDERR_FILENO
, TIOCGWINSZ
, &ws
) == -1 &&
63 ioctl(STDIN_FILENO
, TIOCGWINSZ
, &ws
) == -1) ||
74 size
= min(lines
,cols
/zoom
);
75 size
= ((size
%2)==0?size
-1:size
); //make size odd
76 //printf("%d\n", size);
79 char cifernik
[size
*zoom
][size
];
82 for(y
=0;y
<size
;y
++) for(x
=0;x
<(size
*zoom
);x
++) cifernik
[x
][y
] = color_empty
;
85 if(MINUTE_DOTS
&& size
> 40) for(i
=1;i
<=60;i
++) {
86 phi
= -90+(i
*(360/60));
88 x
= round((r
+polar2x(phi
,r
))*zoom
);
89 y
= round(r
+polar2y(phi
,r
));
90 cifernik
[x
][y
] = color_dot
;
95 phi
= -90+(i
*(360/12));
97 x
= round((r
+polar2x(phi
,r
))*zoom
);
98 y
= round(r
+polar2y(phi
,r
));
100 cifernik
[x
][y
] = '0'+(i
%10);
101 if(i
>9) cifernik
[x
-1][y
] = '0'+(i
/10);
103 cifernik
[x
][y
] = color_number
;
108 phi
= -90+(m
*(360/60));
109 for(r
=0;r
<(size
/2);r
++) {
110 x
= round((size
/2+polar2x(phi
,r
))*zoom
);
111 y
= round(size
/2+polar2y(phi
,r
));
112 cifernik
[x
][y
] = color_m
;
116 phi
= -90+(h
*(double)(360/12));
117 for(r
=0;r
<(size
/3);r
++) {
118 x
= round((size
/2+polar2x(phi
,r
))*zoom
);
119 y
= round(size
/2+polar2y(phi
,r
));
120 cifernik
[x
][y
] = color_h
;
124 phi
= -90+(s
*(360/60));
125 for(r
=0;r
<(size
/2);r
++) {
126 x
= round((size
/2+polar2x(phi
,r
))*zoom
);
127 y
= round(size
/2+polar2y(phi
,r
));
128 cifernik
[x
][y
] = color_s
;
132 cifernik
[(size
/2)*zoom
][size
/2] = color_center
;
134 //cls when terminal size changes
135 if(lines
!= llines
|| cols
!= lcols
) {
142 for(y
=0;y
<size
;y
++) {
143 for(r
=0;r
<=((cols
-(size
*zoom
))/2);r
++) putchar(' ');
144 for(x
=0;x
<((size
*zoom
)-(zoom
-1));x
++) {
145 putchar(cifernik
[x
][y
]);
147 if(y
!=(size
-1)) putchar('\n');
158 cas
= localtime(&cast
);
160 if(cas
->tm_sec
!= s
){
163 render_clock(cas
->tm_hour
,cas
->tm_min
,cas
->tm_sec
); //analog
164 if(SHOW_DIGITS
) printf("\r[%.2d:%.2d:%.2d]",cas
->tm_hour
,cas
->tm_min
,cas
->tm_sec
); //digital
166 if(HI_PRECISION
) { usleep(100000); }
This page took 0.379254 seconds and 4 git commands to generate.