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 HOUR_HEXADECIMAL 1
20 #define HI_PRECISION 1
22 #define DIGITS_HEXADECIMAL 1
24 #define SMOOTH_MOTION 1
28 #define max(a,b) ((a)>=(b)?(a):(b))
29 #define min(a,b) ((a)<=(b)?(a):(b))
30 #define PI 3.141592654
31 #define deg2rad(a) (((a)/180)*PI)
32 //phi = angle, r = length
33 #define polar2x(phi, r) ((r) * cos(deg2rad(phi)))
34 #define polar2y(phi, r) ((r) * sin(deg2rad(phi)))
35 #define cls() printf("\033[2J")
36 #define top() printf("\033[0;0H")
38 int llines
= -1, lcols
= -1;
39 void render_clock(double h
, double m
, double s
) {
41 char color_empty
= ' ';
42 char color_center
= '+';
43 char color_number
= '#';
49 //convert digital time to "analog" time (enables smooth motion)
55 //get size of terminal
59 p = popen("stty size", "r");
60 fscanf(p, "%d %d", &lines, &cols);
63 if ((ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
) == -1 &&
64 ioctl(STDERR_FILENO
, TIOCGWINSZ
, &ws
) == -1 &&
65 ioctl(STDIN_FILENO
, TIOCGWINSZ
, &ws
) == -1) ||
76 size
= min(lines
,cols
/zoom
);
77 size
= ((size
%2)==0?size
-1:size
); //make size odd
78 //printf("%d\n", size);
81 char cifernik
[size
*zoom
][size
];
84 for(y
=0;y
<size
;y
++) for(x
=0;x
<(size
*zoom
);x
++) cifernik
[x
][y
] = color_empty
;
87 if(MINUTE_DOTS
&& size
> 40) for(i
=1;i
<=60;i
++) {
88 phi
= -90+(i
*(360/60));
90 x
= round((r
+polar2x(phi
,r
))*zoom
);
91 y
= round(r
+polar2y(phi
,r
));
92 cifernik
[x
][y
] = color_dot
;
97 phi
= -90+(i
*(360/12));
99 x
= round((r
+polar2x(phi
,r
))*zoom
);
100 y
= round(r
+polar2y(phi
,r
));
102 cifernik
[x
][y
] = '0'+(i
%10);
103 if(HOUR_HEXADECIMAL
) {
104 sprintf(&cifernik
[x
][y
],"%X",i
);
106 if(i
>9) cifernik
[x
-1][y
] = '0'+(i
/10);
109 cifernik
[x
][y
] = color_number
;
114 phi
= -90+(m
*(360/60));
115 for(r
=0;r
<(size
/2);r
++) {
116 x
= round((size
/2+polar2x(phi
,r
))*zoom
);
117 y
= round(size
/2+polar2y(phi
,r
));
118 cifernik
[x
][y
] = color_m
;
122 phi
= -90+(h
*(double)(360/12));
123 for(r
=0;r
<(size
/3);r
++) {
124 x
= round((size
/2+polar2x(phi
,r
))*zoom
);
125 y
= round(size
/2+polar2y(phi
,r
));
126 cifernik
[x
][y
] = color_h
;
130 phi
= -90+(s
*(360/60));
131 for(r
=0;r
<(size
/2);r
++) {
132 x
= round((size
/2+polar2x(phi
,r
))*zoom
);
133 y
= round(size
/2+polar2y(phi
,r
));
134 cifernik
[x
][y
] = color_s
;
138 cifernik
[(size
/2)*zoom
][size
/2] = color_center
;
140 //cls when terminal size changes
141 if(lines
!= llines
|| cols
!= lcols
) {
148 for(y
=0;y
<size
;y
++) {
149 for(r
=0;r
<=((cols
-(size
*zoom
))/2);r
++) putchar(' ');
150 for(x
=0;x
<((size
*zoom
)-(zoom
-1));x
++) {
151 putchar(cifernik
[x
][y
]);
153 if(y
!=(size
-1)) putchar('\n');
164 cas
= localtime(&cast
);
166 if(cas
->tm_sec
!= s
){
169 render_clock(cas
->tm_hour
,cas
->tm_min
,cas
->tm_sec
); //analog
170 if(SHOW_DIGITS
|| DIGITS_HEXADECIMAL
) putchar('\r');
171 if(SHOW_DIGITS
) printf("DEC:[%.2d:%.2d:%.2d]",cas
->tm_hour
,cas
->tm_min
,cas
->tm_sec
); //digital
172 if(SHOW_DIGITS
|| DIGITS_HEXADECIMAL
) putchar(' ');
173 if(DIGITS_HEXADECIMAL
) printf("HEX:[%.2x:%.2x:%.2x]",cas
->tm_hour
,cas
->tm_min
,cas
->tm_sec
); //digital hexadec
175 if(HI_PRECISION
) { usleep(100000); }
This page took 0.334447 seconds and 4 git commands to generate.