编写一个程序,使用ASCII图形将当前系统时间显示为模拟时钟。时钟必须至少显示小时和分钟指针,并且必须具有至少5分钟的足够分辨率。
显示屏可能很小也很丑,但是显示的时间应该很容易辨认。
该程序必须连续运行并更新其状态。如果您的系统可以清除屏幕,请使用它,否则当状态更改时足以重绘时钟。
如果时钟的分辨率至少为1分钟,您将获得-20%的字符数奖励。
编写一个程序,使用ASCII图形将当前系统时间显示为模拟时钟。时钟必须至少显示小时和分钟指针,并且必须具有至少5分钟的足够分辨率。
显示屏可能很小也很丑,但是显示的时间应该很容易辨认。
该程序必须连续运行并更新其状态。如果您的系统可以清除屏幕,请使用它,否则当状态更改时足以重绘时钟。
如果时钟的分辨率至少为1分钟,您将获得-20%的字符数奖励。
Answers:
刻度和小时标签位于单位圆上。
H
和M
围绕时钟中心旋转,分别显示完成的小时数和分钟数。
S
每秒几次更新其位置。
显示了两个版本:一个在笛卡尔平面上绘制文本的版本,另一个在网格中显示文本字符的版本。
此版本将字符绘制到笛卡尔平面中。
d = Dynamic; t = Table; x = Text;i_~u~k_ := {Sin[2 \[Pi] i/k], Cos[2 \[Pi] i/k]};
d[{f = Date[], Clock[{1, 1}, 1]}]
Graphics[d@{t[x[".", u[i, 60]], {i, 60}],t[x[i, u[i, 12]], {i, 12}],
x["H", .7 u[f〚4〛, 12]],x["M", .8 u[f〚5〛, 60]],x["S", .9 u[f〚6〛, 60]]}]
下面的时钟显示了时间3:08:17。
终端或网格版本:430 316个字符(253红利贴现)
此版本的工作原理几乎相同,但是将字符放置在61 x 61的单元格中,而不是在笛卡尔平面中。它仍然可以打高尔夫球,但是我只想在Mathematica中显示一个(更尖)的终端式输出。
d = Dynamic; i_~u~k_ := Round /@ (10 {Sin[2 \[Pi] (i + 3 k/4)/k],
Cos[2 \[Pi] (i + 3 k/4)/k]}); d[{f = Date[], Clock[]}]
z = Round /@ (# u[f[[#2]], #3] + 11) -> #4 &;
t = Table[( u[i, 12] + 11) -> i, {i, 12}];
d@Grid[ReplacePart[ConstantArray["", {21, 21}],
Join[z @@@ {{.9, 5, 60, "M"}, {.8, 4, 12, "H"}},
DeleteCases[Table[( u[i, 60] + 11) -> "*", {i, 60}], x_ /; MemberQ[t[[All, 1]], x[[1]]]], t]]]
下面的时钟显示11:06。
只是为了好玩:
这是模拟时钟的非Ascii版本。(60个字符)未使用外部库。
Dynamic@Refresh[ClockGauge@AbsoluteTime[], UpdateInterval -> 1]
(这仅在Chrome中有效,因为我滥用了将元素ID添加到全局范围的事实)。
(function loop(){
M=Math;p=M.PI/2;z=M.pow;q=M.sqrt;d=new Date();h=(d.getHours()%12/3*p+p)%(p*4);m=(d.getMinutes()/15*p+p)%(p*4);s=(d.getSeconds()/15*p+p)%(p*4);e=49;o='';
for(r=0;r<99;r++){
for(c=0;c<99;c++){
d=q(z(r-e,2)+z(c-e,2));
a=(M.atan2(e-r,e-c)+p*4)%(p*4);
E=(d<e*.8&&M.abs(m-a)*d<.5) || (d<e*.5&&M.abs(h-a)*d<.5) || (d<e*1&&M.abs(s-a)*d<.5);
o+=d-e>0||d<1||E||(e-d<5&&a%p==0)?'●':'○';
//■□●○
}
o+='\n';
}
O.innerText=o
setTimeout(loop,1000);
})()
高尔夫球(370):
!function L(){p=M.PI/2;q=p*4;P=M.pow;d=new Date();s=(d.getSeconds(S=d.getMinutes(e=40))/15*p+p)%q;m=(S/15*p+p)%q;h=(d.getHours(A=M.abs)%12/3*p+S/180*p+p)%q;for(r=o='';r<81;r++,o+='\n')for(c=0;c<81;){d=M.sqrt(P(r-e,2)+P(c-e,2));a=(M.atan2(e-r,e-c++)+q)%q;o+='○●'[d-e>0|d<e*.8&A(m-a)*d<1|d<e/2&A(h-a)*d<1|d<e&A(s-a)*d<1|e-d<5&a%p==0]}O.innerText=o;setTimeout(L,9)}(M=Math)
样本输出(演示中的更多内容):
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●○○○○○○●○○○○○○●●●●●●●●●●●●●●
●●●●●●●●●●●●○○○○○○○○●○○○○○○○○●●●●●●●●●●●●
●●●●●●●●●●○○○○○○○○○○●○○○○○○○○○○●●●●●●●●●●
●●●●●●●●○○○○○○○○○○○○●○○○○○○○○○○○○●●●●●●●●
●●●●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●●●●
●●●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●●●
●●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●●
●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●
●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●
●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●
●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●
●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●
●●○○○○○○○○○○○○○○○○○○○○○○○○○●○○○○○○○○○○○●●
●○○○○○○○○○○○○○○○○○○○○○○○○○●●○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○○○○○○○○●●○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○○○○○○○●●○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○○○○○○●●○○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○○○○○●○○○○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○○○○●○○○○○○○○○○○○○○○○○○●
●●●●●○○○○○○○○○○○○○○○●○○○○○○○○○○○○○○○●●●●●
●○○○○○○○○○○○○○○○○○○●○●○○○○○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○○●○○●○○○○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○●○○○○●●○○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○○●○○○○○●●○○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○○●○○○○○○○●●○○○○○○○○○○○○○●
●○○○○○○○○○○○○○○○●●○○○○○○○○●●○○○○○○○○○○○○●
●●○○○○○○○○○○○○○○●○○○○○○○○○○○●○○○○○○○○○○●●
●●○○○○○○○○○○○○○●○○○○○○○○○○○○○●○○○○○○○○○●●
●●●○○○○○○○○○○○○●○○○○○○○○○○○○○○●○○○○○○○●●●
●●●○○○○○○○○○○○●○○○○○○○○○○○○○○○○●○○○○○○●●●
●●●●○○○○○○○○○○●○○○○○○○○○○○○○○○○○●○○○○●●●●
●●●●○○○○○○○○○●○○○○○○○○○○○○○○○○○○○●●○○●●●●
●●●●●○○○○○○○●●○○○○○○○○○○○○○○○○○○○○●●●●●●●
●●●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●●●
●●●●●●●○○○○○○○○○○○○○○○○○○○○○○○○○○○●●●●●●●
●●●●●●●●○○○○○○○○○○○○●○○○○○○○○○○○○●●●●●●●●
●●●●●●●●●●○○○○○○○○○○●○○○○○○○○○○●●●●●●●●●●
●●●●●●●●●●●●○○○○○○○○●○○○○○○○○●●●●●●●●●●●●
●●●●●●●●●●●●●●○○○○○○●○○○○○○●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
每秒打印一个新时钟,分针每分钟更新一次。
import math,time
def p(t,r):c[int(25-r*math.cos(t))][int(25+r*math.sin(t))]='*'
while 1:
time.sleep(1);c=[[' ']*50 for i in range(50)];t=time.localtime();h=t.tm_hour*6.283+t.tm_min/9.549
for i in range(999):
p(i/158.0,24);p(h,i*.02);p(h/12,i*.01)
for q in range(12):p(q/1.91,24-i*.005)
for y in range(50):print''.join(c[y])
它打印的时钟看起来像这样(在我的终端中没有那么长):
**************
**** * ****
*** * ***
*** * ***
** ** * ** **
** * * **
** ** ** **
* * * **
** **
** **
** **
* *
*** ***
* *** *** *
** ** ** **
* *
* *
** **
* *
* * *
* ****** *
* ****** *
* ****** *
* ***** *
***** * ******
* ** *
* ** *
* * *
* ** *
* ** *
** ** **
* * *
* * *
** ** ** **
* *** *** *
*** ***
* *
** **
** **
** **
* * * *
** ** ** **
** * * **
** ** * ** **
*** * ***
*** * ***
**** * ****
**************
*
可以在此处或此页面上找到最终版本和升级版本: 极客的ascii-clock。但是不要使用它!阅读此答案末尾的注释,已警告您!请改用此Perl版本!
可扩展和可编辑:
time 2>&1 /tmp/asci-art.sh 10 10 10
. . . 12. . .
11. . 1
. .
. .
. .
10 2
. H M .
. .
. .
. .
9 3
. .
. .
. .
. .
8 4
. .
. .
. .
7 . . 5
. . . 6 . . .
real 0m0.356s
user 0m0.348s
sys 0m0.004s
在不到一秒钟的时间内在10H10绘制21x21(10x2 + 1)时钟。
这接受3个参数:Usage: ascii-clock.sh [ray of clock] [Hour] [Min]
默认射线为12,时钟绘制为2 x ray + 1
线条的高度和宽度的两倍,这是因为要尝试获得圆形而增加了空间。
如果使用0
或1
参数调用脚本,则会循环重绘每分钟。否则,如果至少指定了小时(第二个参数),它将只绘制一次并退出。
所述H
标记位于在射线的70%和M
标记位于在射线的90%。
不使用外部二进制文件,例如date
或bc
为平局!
(感谢@manatwork提供的内置功能 read -t
,如果/bin/sleep
)。
所以所有这些都是由内置的 shell命令。
它使用ANSI序列,但仅用于循环并使标记加粗。
#!/bin/bash
# Analog clock in Ascii-Art written in BASH V4.2 +=
RAY=${1:-12} NowH=$2 NowM=$3
sqrt() {
local -a _xx=(600000 200000)
local _x1=${_xx[$(($1&1))]} _x0=1
while [ $_x0 -ne $_x1 ] ;do
_x0=$_x1
[ $_x0 -eq 0 ] && _x1=0000 ||
printf -v _x1 "%u" $(( (${_x0}000 + ${1}00000000000/${_x0} )/2 ))
printf -v _x1 "%.0f" ${_x1:0:${#_x1}-3}.${_x1:${#_x1}-3}
done
_x1=0000$_x1
printf ${2+-v} $2 "%.3f" ${_x1:0:${#_x1}-4}.${_x1:${#_x1}-4}
}
clksin() { # $1:moment [0-60], $2:path length, $3:variable name
local _csin=(0 104528 207912 309017 406737 500000 587785 669131
743145 809017 866025 913545 951057 978148 994522 1000000)
local xsign=1 x=$1 ysign=-1 y=$1
[ $x -gt 30 ] && xsign=-1 x=$((60-x))
[ $x -gt 15 ] && x=$((30-x))
x=00000$((RAY*1000000+xsign*${2:-10}*${_csin[$x]}))
[ $y -gt 30 ] && y=$((60-y))
[ $y -gt 15 ] && ysign=1 y=$((30-y))
y=00000$((RAY*1000000+ysign*${2:-10}*${_csin[15-$y]}))
printf ${3+-v} $3 "%.0f %.0f" \
${y:0:${#y}-6}.${y:${#y}-6} ${x:0:${#x}-6}.${x:${#x}-6}
};
MLEN=000$((900*RAY))
printf -v MLEN "%.0f" ${MLEN:0:${#MLEN}-3}.${MLEN:${#MLEN}-3}
HLEN=000$((700*RAY))
printf -v HLEN "%.0f" ${HLEN:0:${#HLEN}-3}.${HLEN:${#HLEN}-3}
declare -A ticks
for ((i=1;i<=12;i++));do
clksin $((5*(i%12))) $RAY tick
ticks[$tick]=$i
done
while :;do
[ "$NowM" ] || printf -v NowM "%(%M)T\n" -1
clksin ${NowM#0} $MLEN NowM
[ "$NowH" ] || printf -v NowH "%(%H)T\n" -1
clksin $((5*(${NowH#0}%12))) $HLEN NowH
[ "$2" ] || echo -en \\e[H; # ANSI sequence for top left of console
for ((i=0;i<=2*RAY;i++));do
x=$((RAY-i))
sqrt $((RAY**2 - ${x#-}**2 )) y0
printf -v y0 "%.0f" $y0
for ((l=0;l<=2*RAY;l++));do
y=$((RAY-l));
sqrt $((RAY**2 - ${y#-}**2 )) x0
printf -v x0 "%.0f" $x0
if [ "${ticks["$i $l"]}" ] ;then
printf "%-2s" ${ticks["$i $l"]}
elif [ ${x#-} -eq $x0 ] || [ ${y#-} -eq $y0 ] ;then
echo -n .\
elif [ "$i $l" = "$NowM" ] ;then
echo -en \\e[1mM\ \\e[0m
elif [ "$i $l" = "$NowH" ] ;then
echo -en \\e[1mH\ \\e[0m
else
echo -n \ \
fi
done
echo -e \\e[K
done
echo -en \\e[J
[ "$2" ] && break # Exit if at least Hour was specified
printf -v SleepS "%(%S)T" -1
read -t $((60-${SleepS#0})) foo
unset NowH NowM
done
可以这样运行:
for time in 10:10 15:00 12:30 06:00 09:15 16:40 ;do
echo - $time -{,}{,}{,}
./ascii-clock.sh 5 ${time//:/ }
echo -{,,,,,}{,}
done |
sed 's/\o033\[\(.m\|[JK]\)//g;/-$/!s/$/|/;s/-$/+/' |
column -c 80
这将产生类似以下内容:
+- 10:10 - - - - - - - + - 12:30 - - - - - - - + - 09:15 - - - - - - - +
| . . 12. . | . . 12. . | . . 12. . |
| 11 1 | 11 H 1 | 11 1 |
| 10 2 | 10 2 | 10 2 |
|. H M . | . . | . . |
|. . | . . | . . |
|9 3 | 9 3 | 9 H M 3 |
|. . | . . | . . |
|. . | . . | . . |
| 8 4 | 8 4 | 8 4 |
| 7 5 | 7 M 5 | 7 5 |
| . . 6 . . | . . 6 . . | . . 6 . . |
+- - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - +
+- 15:00 - - - - - - - + - 06:00 - - - - - - - + - 16:40 - - - - - - - +
| . . 12. . | . . 12. . | . . 12. . |
| 11 M 1 | 11 M 1 | 11 1 |
| 10 2 | 10 2 | 10 2 |
|. . | . . | . . |
|. . | . . | . . |
|9 H 3 | 9 3 | 9 3 |
|. . | . . | . . |
|. . | . . | . M H . |
| 8 4 | 8 4 | 8 4 |
| 7 5 | 7 H 5 | 7 5 |
| . . 6 . . | . . 6 . . | . . 6 . . |
+- - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - +
或者可以运行为:
xterm -geom 86x44 -bg black -fg grey -e ./ascii-clock.sh 21 &
xterm -geom 103x52 -fn nil2 -bg black -fg grey -e ./ascii-clock.sh 25 &
gnome-terminal --geometry 103x52 --zoom .5 -e "./ascii-clock.sh 25" &
#!/bin/bash
# Analog clock in Ascii-Art written in BASH V4.2 +=
RAY=${1:-12} NowH=$2 NowM=$3
sqrt() {
local -a _xx=(600000 200000)
local _x1=${_xx[$(($1&1))]} _x0=1
while [ $_x0 -ne $_x1 ] ;do
_x0=$_x1
[ $_x0 -eq 0 ] && _x1=0000 ||
printf -v _x1 "%u" $(( (${_x0}000 + ${1}00000000000/${_x0} )/2 ))
printf -v _x1 "%.0f" ${_x1:0:${#_x1}-3}.${_x1:${#_x1}-3}
done
_x1=0000$_x1
printf ${2+-v} $2 "%.3f" ${_x1:0:${#_x1}-4}.${_x1:${#_x1}-4}
}
clksin() { # $1:moment [0-60], $2:path length, $3:variable name
local _csin=(0 104528 207912 309017 406737 500000 587785 669131
743145 809017 866025 913545 951057 978148 994522 1000000)
local xsign=1 x=$1 ysign=-1 y=$1
[ $x -gt 30 ] && xsign=-1 x=$((60-x))
[ $x -gt 15 ] && x=$((30-x))
x=00000$((RAY*1000000+xsign*${2:-10}*${_csin[$x]}))
[ $y -gt 30 ] && y=$((60-y))
[ $y -gt 15 ] && ysign=1 y=$((30-y))
y=00000$((RAY*1000000+ysign*${2:-10}*${_csin[15-$y]}))
printf ${3+-v} $3 "%.0f %.0f" \
${y:0:${#y}-6}.${y:${#y}-6} ${x:0:${#x}-6}.${x:${#x}-6}
};
MLEN=000$((900*RAY))
printf -v MLEN "%.0f" ${MLEN:0:${#MLEN}-3}.${MLEN:${#MLEN}-3}
HLEN=000$((700*RAY))
printf -v HLEN "%.0f" ${HLEN:0:${#HLEN}-3}.${HLEN:${#HLEN}-3}
declare -A ticks
for ((i=1;i<=12;i++));do
clksin $((5*(i%12))) $RAY tick
ticks[$tick]=$i
done
while :;do
[ "$NowM" ] || printf -v NowM "%(%M)T\n" -1
unset MPath
declare -A MPath
for ((i=1;i<=MLEN;i++));do
clksin ${NowM#0} $i tick
MPath[$tick]=M
done
[ "$NowH" ] || printf -v NowH "%(%H)T\n" -1
unset HPath
declare -A HPath
for ((i=1;i<=HLEN;i++));do
clksin $((5*(${NowH#0}%12))) $i tick
HPath[$tick]=H
done
[ "$2" ] || echo -en \\e[H; # ANSI sequence for top left of console
for ((i=0;i<=2*RAY;i++));do
x=$((RAY-i))
sqrt $((RAY**2 - ${x#-}**2 )) y0
printf -v y0 "%.0f" $y0
for ((l=0;l<=2*RAY;l++));do
y=$((RAY-l));
sqrt $((RAY**2 - ${y#-}**2 )) x0
printf -v x0 "%.0f" $x0
if [ "${MPath["$i $l"]}" ] ;then
echo -en \\e[1m${MPath["$i $l"]}\ \\e[0m
elif [ "${HPath["$i $l"]}" ] ;then
echo -en \\e[1m${HPath["$i $l"]}\ \\e[0m
elif [ "${ticks["$i $l"]}" ] ;then
printf "%-2s" ${ticks["$i $l"]}
elif [ ${x#-} -eq $x0 ] || [ ${y#-} -eq $y0 ] ;then
echo -n .\
else
echo -n \ \
fi
done
echo -e \\e[K
done
echo -en \\e[J
[ "$2" ] && break # Exit if at least Hour was specified
printf -v SleepS "%(%S)T" -1
read -t $((60-${SleepS#0})) foo
unset NowH NowM
done
可能产生:
+- 10:10 - - - - - - - + - 12:30 - - - - - - - + - 09:15 - - - - - - - +
| . . 12. . | . . 12. . | . . 12. . |
| 11 1 | 11 H 1 | 11 1 |
| 10 2 | 10 H 2 | 10 2 |
|. H M . | . H . | . . |
|. H H H M M M . | . H . | . . |
|9 3 | 9 3 | 9 H H H H M M M M 3 |
|. . | . M . | . . |
|. . | . M . | . . |
| 8 4 | 8 M 4 | 8 4 |
| 7 5 | 7 M 5 | 7 5 |
| . . 6 . . | . . 6 . . | . . 6 . . |
+- - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - +
+- 15:00 - - - - - - - + - 06:00 - - - - - - - + - 16:40 - - - - - - - +
| . . 12. . | . . 12. . | . . 12. . |
| 11 M 1 | 11 M 1 | 11 1 |
| 10 M 2 | 10 M 2 | 10 2 |
|. M . | . M . | . . |
|. M . | . M . | . . |
|9 H H H H 3 | 9 3 | 9 3 |
|. . | . H . | . M M M H H H . |
|. . | . H . | . M H . |
| 8 4 | 8 H 4 | 8 4 |
| 7 5 | 7 H 5 | 7 5 |
| . . 6 . . | . . 6 . . | . . 6 . . |
+- - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - - - +
要么
. . . . 12. . . .
. . . . . .
. . . .
. 11 1 .
. .
. .
. .
. .
. .
. .
10 2
. M .
. M M M .
. H M .
. H H M M .
. H M .
. H H H M M M .
. H M .
. H H M M .
. H M .
9 H M 3
. .
. .
. .
. .
. .
. .
. .
. .
. .
8 4
. .
. .
. .
. .
. .
. .
. 7 5 .
. . . .
. . . . . .
. . . . 6 . . . .
该功能仅在最近的Linux上有效,因为它用于/proc/timer_list
计算每次刷新之间睡眠的秒数。
#!/bin/bash
# Analog clock in Ascii-Art written in BASH V4.2 +=
RAY=${1:-12} NowH=$2 NowM=$3
# Hires Sleep Until
# there is a need to store offset in a static var
mapfile </proc/timer_list _timer_list
for ((_i=0;_i<${#_timer_list[@]};_i++));do
[[ ${_timer_list[_i]} =~ ^now ]] && TIMER_LIST_SKIP=$_i
[[ ${_timer_list[_i]} =~ offset:.*[1-9] ]] && \
TIMER_LIST_OFFSET=${_timer_list[_i]//[a-z.: ]} && \
break
done
unset _i _timer_list
readonly TIMER_LIST_OFFSET TIMER_LIST_SKIP
sleepUntilHires() {
local slp tzoff now quiet=false nsnow nsslp
local hms=(${1//:/ })
mapfile -n 1 -s $TIMER_LIST_SKIP nsnow </proc/timer_list
printf -v now '%(%s)T' -1
printf -v tzoff '%(%z)T\n' $now
nsnow=$((${nsnow//[a-z ]}+TIMER_LIST_OFFSET))
nsslp=$((2000000000-10#${nsnow:${#nsnow}-9}))
tzoff=$((0${tzoff:0:1}(3600*${tzoff:1:2}+60*${tzoff:3:2})))
slp=$(( ( 86400 + ( now - now%86400 ) +
10#$hms*3600+10#${hms[1]}*60+10#${hms[2]} -
tzoff - now - 1
) % 86400)).${nsslp:1}
read -t $slp foo
}
sqrt() {
local -a _xx=(600000 200000)
local _x1=${_xx[$(($1&1))]} _x0=1
while [ $_x0 -ne $_x1 ] ;do
_x0=$_x1
[ $_x0 -eq 0 ] && _x1=0000 ||
printf -v _x1 "%u" $(( (${_x0}000 + ${1}00000000000/${_x0} )/2 ))
printf -v _x1 "%.0f" ${_x1:0:${#_x1}-3}.${_x1:${#_x1}-3}
done
_x1=0000$_x1
printf ${2+-v} $2 "%.3f" ${_x1:0:${#_x1}-4}.${_x1:${#_x1}-4}
}
clksin() { # $1:moment [0-60], $2:path length, $3:variable name
local _csin=(0 104528 207912 309017 406737 500000 587785 669131
743145 809017 866025 913545 951057 978148 994522 1000000)
local xsign=1 x=$1 ysign=-1 y=$1
[ $x -gt 30 ] && xsign=-1 x=$((60-x))
[ $x -gt 15 ] && x=$((30-x))
x=00000$((RAY*1000000+xsign*${2:-10}*${_csin[$x]}))
[ $y -gt 30 ] && y=$((60-y))
[ $y -gt 15 ] && ysign=1 y=$((30-y))
y=00000$((RAY*1000000+ysign*${2:-10}*${_csin[15-$y]}))
printf ${3+-v} $3 "%.0f %.0f" \
${y:0:${#y}-6}.${y:${#y}-6} ${x:0:${#x}-6}.${x:${#x}-6}
};
SLEN=000$((870*RAY))
printf -v SLEN "%.0f" ${SLEN:0:${#SLEN}-3}.${SLEN:${#SLEN}-3}
MLEN=000$((780*RAY))
printf -v MLEN "%.0f" ${MLEN:0:${#MLEN}-3}.${MLEN:${#MLEN}-3}
HLEN=000$((650*RAY))
printf -v HLEN "%.0f" ${HLEN:0:${#HLEN}-3}.${HLEN:${#HLEN}-3}
declare -A ticks
for ((i=1;i<=12;i++));do
clksin $((5*(i%12))) $RAY tick
ticks[$tick]=$i
done
while :;do
[ "$NowM" ] || printf -v NowM "%(%M)T\n" -1
unset MPath
declare -A MPath
for ((i=1;i<=MLEN;i++));do
clksin ${NowM#0} $i tick
MPath[$tick]=M
done
[ "$NowH" ] || printf -v NowH "%(%H)T\n" -1
unset HPath
declare -A HPath
for ((i=1;i<=HLEN;i++));do
clksin $((5*(${NowH#0}%12))) $i tick
HPath[$tick]=H
done
printf -v NowS "%(%S)T\n" -1
clksin ${NowS#0} $SLEN STick
[ "$2" ] || echo -en \\e[H; # ANSI sequence for top left of console
for ((i=0;i<=2*RAY;i++));do
x=$((RAY-i))
sqrt $((RAY**2 - ${x#-}**2 )) y0
printf -v y0 "%.0f" $y0
for ((l=0;l<=2*RAY;l++));do
y=$((RAY-l));
sqrt $((RAY**2 - ${y#-}**2 )) x0
printf -v x0 "%.0f" $x0
if [ "$i $l" = "$STick" ] ;then
echo -en \\e[1ms\ \\e[0m
elif [ "${MPath["$i $l"]}" ] ;then
echo -en \\e[1m${MPath["$i $l"]}\ \\e[0m
elif [ "${HPath["$i $l"]}" ] ;then
echo -en \\e[1m${HPath["$i $l"]}\ \\e[0m
elif [ "${ticks["$i $l"]}" ] ;then
printf "%-2s" ${ticks["$i $l"]}
elif [ ${x#-} -eq $x0 ] || [ ${y#-} -eq $y0 ] ;then
echo -n .\
else
echo -n \ \
fi
done
echo -e \\e[K
done
echo -en \\e[J
[ "$2" ] && break # Exit if at least Hour was specified
printf -v SleepS "%(%s)T" -1
printf -v SleepS "%(%T)T" $((1+SleepS))
sleepUntilHires $SleepS
unset NowH NowM
done
根据@manatwork的要求,还有一个高尔夫球版本。
此版本是彩色的,并且在角落显示数字时间。
#!/bin/bash
W=/proc;J=${1:-12} B=$2 A=$3 LANG=C R=$W/timer_list;if [ -f $R ];then Q=10
mapfile <$R e;for ((P=0;P<${#e[@]};P++));do ((Q+=${#e[P]}));[[ ${e[P]} =~ ^now
]]&&U=$Q;[[ ${e[P]} =~ offset:.*[1-9] ]]&&a=${e[P]//[a-z.: ]}&&break;done;c(){
local q p;read -N$U q <$R;q=${q%% nse*};q=$[${q##* }+a];p=$[2000000000-10#${q:
${#q}-9}];read -t .${p:1} M;};else c(){ local H;read -d\ H < $W/upti*;H=$[200
-10#${H#*.}];read -t .${H:1} M;};fi;u(){ local E=({6,2}00000) F=${E[$1&1]} G=1
while [ $G -ne $F ];do G=$F;[ $G -eq 0 ]&&F=0000||printf -v F "%u" $(((${G}000
+${1}00000000000/${G})/2));printf -v F "%.0f" ${F:0:${#F}-3}.${F:${#F}-3};done
F=0000$F;printf -v $2 "%.3f" ${F:0:${#F}-4}.${F:${#F}-4};};g(){ local t=($[7#0
] 104528 207912 309017 406737 500000 587785 669131 743145 809017 866025 913545
951057 978148 994522 1000000) j=1 x=$1 h=-1 y=$1;[ $x -gt 30 ]&&j=-1 x=$[60-x]
((x>15))&&x=$[30-x];x=00000$[J*1000000+j*${2:-10}*${t[$x]}];((y>30))&&y=$[60-y
];((y>15))&&h=1 y=$[30-y];y=00000$[J*1000000+h*${2:-10}*${t[15-y]}];printf -v\
$3 "%.0f %.0f" ${y:0:${#y}-6}.${y:${#y}-6} ${x:0:${#x}-6}.${x:${#x}-6};};v=000
v+=$((870 *J));printf -v v "%.0f" ${v:0:${#v}-3}.${v:${#v}-3};C=000$((780*J));
printf -v C "%.0f" ${C:0:${#C}-3}.${C:${#C}-3};D=000$[650*J];printf -v D %.f \
${D:0:${#D}-3}.${D:${#D}-3};declare -A m;for ((i=1;i<=12;i++));do g $[5*(i%12)
] $J w;m[$w]=$i;done;printf -v T "\e[1m%s\e[0m " . + \* o O;T=(${T});m["${J: \
} $J"]=${T} ;printf "\e[?25l\e[H\e[J";trap "printf '\e[?12l\e[?25h\e[$((2*J +3
))H\e[J';exit" 0 1 2 3 6 9 15; printf -v S "\\e[1;%dH%%(%%H)T\\e[%dH%%(%%M${Z:
})T\\e[%d;%dH%%(%%S)T" $[4*J] $[2*J+1] $[2*J+1] $[4*J];declare -A V;V["$[2 * J
] $[2*$J]"]=" ";while :;do [ "$A" ]||printf -v A "%(%M)T" -1;unset r;declare\
-A r;for ((i=1;i<=C;i++));do g ${A#0} $i w;r[$w]=M;done;[ "$B" ]||printf -v \
B "%(%H)T" -1;unset s;declare -A s;for ((i=1;i<=D;i++));do g $((5*( ${B#0}%12)
)) $i w;s[$w]=H;done;printf -v z "%(%S)T" -1;g ${z#0} $v n;[ "$2" ]||echo -en\
\\e[H;for ((i=0;i<=2*J;i++));do x=$[J-i];u $[J*J-${x#-}**2] N;printf -v N${Z:
} %.f $N;for ((l=0;l<=2*J;l++));do y=$[J-l];u $[J*J-${y#-}**2] O;printf -v O \
%.f $O;c=" ";if [ "$i $l" = "$n" ];then c=$'\e[36;1ms \e[m';elif [ "${r["${i:
} $l"]}" ] ;then c=$'\e[32;1m'${r["$i $l"]}$' \e[0m';elif [ "${s["$i $l"]}" ];
then c=$'\e[34;1m'${s["$i $l"]}$' \e[0m';elif [ "${m["$i $l"]}" ];then printf\
-v c "%-2s" "${m["$i $l"]}";elif [ ${x#-} -eq $O ] || [ ${y#-} -eq $N ] ;then
c=.\ ;else c=" ";fi;[ "$c" != "${V["$i $l"]}" ]&& V["$i $l"]="$c" && printf \
"\e[%s;%sH%-2s" $((1+i)) $[1+l*2] "$c";done;done;[ "$2" ] &&break;printf "${Z:
}\e[H\e[7mS\e[0m";c;printf "\e[H $S" -1 -1 -1;m["$J $J"]=${T[$[10#$z%${#T[@]}]
]};unset B A;done
因为这是bash 程序语言,而bash不是一种编程语言,因此暂时不能很好地使用它。
仅用5个小时就可以看到一些内存消耗的演示,并绘制了7个字符长的射线:
$ ascii-clock.sh 7
After PMem PCpu Mem
0'30" 0.0% 21.6% 12.98M
10'30" 1.0% 20.9% 48.91M
1h 0'30" 5.6% 20.8% 228.63M
2h 0'31" 11.2% 20.8% 444.25M
3h 0'32" 16.8% 20.8% 659.91M
5h 0'00" 27.9% 20.8% 1.064G
这样做的主要优点是,当我需要内存时,我只需要杀死时钟即可。
(注意:我已经将它,perl版本和javascript版本合并到了ascii-clock上,以供极客使用;-)
bash
4.1 上进行了尝试。在4.2上,确实可以连续运行,不需要命令行参数。
bash
就是一个很好的证明。(/我戴上帽子,点击上投票链接),但就代码高尔夫挑战的精神而言,那些2529个字符仍然可以减少:“代码高尔夫是在源代码最少字节中解决特定问题的竞赛。 ”
import time as T
while 1:t=T.localtime();m=t.tm_min/5;l=[12]+range(1,12);l[m]='';l[t.tm_hour%12]='H';l[m]+='M';a=' %s\n';print(a+('%s'+a)*5+a)%tuple(str(l[x])for x in[0,11,1,10,2,9,3,8,4,7,5,6]);T.sleep(9)
它非常难看,但可读性强。每9秒打印一次(如果需要,您可以更改为1秒),每5分钟更新一次。我没有在python中进行代码打高尔夫球的经验,因此我希望可以对其进行改进。
输出示例:
12
11 1
10 2
9 M
8 4
7 H
6
干净,圆形,带有第二个刻度,并且每秒钟更新一次。
perl -E '
$r=11;$p=atan2(1,1)/7.5;sub c{($A,$R,$C)=@_;$a[$r-$R*cos($A*$p)][
$r+$R*sin($A*$p)]=$C." "x($C!~/../)};while(::){@a=map{[map{" "}(
0..$r*2)]}(0..$r*2);map{c$_*5,$r,$_}(1..12);@t=localtime;for$i(qw
|H:6:5:2 M:8:1:1 s:9:1:0 |){($S,$P,$F,$T)=split":",$i;map{c$F*$t[
$T],$_,$S}(do{$T?1:$P}/10*$r..$P/10*$r)};map{say@{$_}}@a;sleep 1}
'
在24行控制台上看起来不错(00:12:56):
12
11 1
s
10 H 2
H
H
H M M
H M M M
M M M
9 3
8 4
7 5
6
还有一个彩色,更好,更聪明的版本:
#! /usr/bin/perl
use Time::HiRes qw|sleep time|
;$h=11;$h=$ARGV[0]if$ARGV[0];$P=atan2
(1,1)/7.5;$V =4*$h; $v= 2* $h+ 1;@r=(0..2*$v)
;sub p{printf @_ }sub b{ return"\e[1m"
.pop."\e[0m" };$ |=p"\e[?25".
"l\e[H\e[" ."J" ;$ SIG{ 'INT'}=sub
{p"\e[?1" ."2l" ."\e" ."[?25h".
"\e[%dH" ."\e" ."[J" ,$v+2;exit;
};@z=map {[map{" "
}@r] }(0 ..2*$v);
@Z=map{[@ {$z[$_]}]}@r
;sub c{($A,$r ,$s )=@_;$z[$h-$r*cos
($A*$P) +.5 ][$h+$ r*sin($A*$P)+.5]=$s;}
for$x( 0..$h) {$y= int(sqrt($h**2 -$x**2
)+.5);$ z[$h-$x][$h-$ y]=".";$z[$h+$x ][$h-$y
]="."; $z[$h-$x][$h+$ y]=".";$z[$h+$x ][$h+$
y]="."; $z[$h-$y][$h-$ x]=".";$z[$h+$y ][$h-$x
]="."; $z[$h-$y][$h+$x]=".";$z[$h+ $y][$h
+$x]="."};map{ c$_*5,$h,b$_}(1..12); @R=map{[@{$z[
$_]}]}@r;while (::){@t=localtime; p"\e[H\e[1;$
{V}H%0" ."2d\e[${v}H%02d\e" ."[${v
};${ V }H%02d",$t[2],$t[ 1],$t[
0];@z= map{[ @{$R[ $_]}]}(
0..2*$ v);for
$i('H:' .'65:5:'
.'2:4', "" x1 .'M:78:'
."1:1" .":2", "s:8". "7:1:"
.'0:6'){($ l,$p,$F,$u,$
c)=split ":",$i;map
{c$F*$t [$u],$_
,b("\e[" ."3${c}m$
l")}(do{$u ?1:$ p} / 100*$h..$p
/100*$h);} $z[$ h][ $h]= b((".","+"
,"*","o","O") [$t [0]%5]);for$x
(@r){for$y(@r ){$ Z[$x][$y]ne$z
[$x][$y]?p"\e[%d;%dH".$z [ $x] [$y],$x+1,2*$
y+1:''};};@Z=map{[@{$z[$_]}]}@r;$n=1-$1
if time=~/(\..*)$/;p"\e[H\e[7m"
."S\e[0m";sleep$n}
该版本与其他答案密切相关,其主要优点是:您可以暂时安静地运行它! 因此,您可以在此处或在此ascii时钟上找到极客的升级版本网页上。
作为一个证明,在perl中执行大约相同的操作需要更少的资源:
$ ascii-clock.pl 7
After PMem PCpu Mem
0' 0" 0.0% 0.0% 23.5M
10'30" 0.0% 0.0% 23.5M
1h 0' 0" 0.0% 0.0% 23.5M
2h 0' 0" 0.0% 0.0% 23.5M
具有大致相同的功能:
s
为第二个处理程序绘制一个圆点。S
时提示左上角的a (查找与bash版本的区别)加
-a
论点以小时为单位绘制小时和分钟路径(11h59放置小时路径大约为12h)。使用以下(美丽的)图片:
比您可以简单地:
curl http://i.stack.imgur.com/xvbHP.png |
perl -e 'use GD;GD::Image->trueColor(1);$i=GD::Image->newFromPng(
STDIN);my($x,$y)=$i->getBounds();for my$k(0..$x-1){for my$l(0
..$y-1){$_.=pack"UUU",$i->rgb($i->getPixel($k,$l))};};eval'
好的,这需要安装gd2-perl。但你可以取代curl
由wget -O -
;-)
(注意:此图片接近1.5Kb。我构建了另一张相同的图片,但长度为900字节。您可能会发现此图片,以及在ascii-clock上适用于极客的javascript版本的图片:-)
eval
按print
顺序替换为;-)
while 1 {scan [clock format [clock seconds] -format %k-%M] %d-%d h m
regsub -all \ +|. "oaosocowoeouooovoioxozom r n\n" \ {&} p
lset p [set h [expr $h%12*2]] h
lset p [set m [expr $m/5*2]] [expr $h-$m?"m":"x"]
puts [string map /\ $p {rr/nrzmrann xrrr snnimrrrcnn vrrr wnnromrenrru}]}
好的,这里有一些解释:
while 1 {...}
-好的,忘了解释。regsub -all \ +|. "oaosocowoeouooovoioxozom r n\n" \ {&} p
替换+|.
为_{\0}
并将结果存储在中p
。p
实际上是一本混乱的字典,其中缺少第一个键(或者只是一个包含奇数个元素的列表)。lset p [set h [expr $h%12*2]] h
在替换清单中设置小时lset p [set m [expr $m/5*2]] [expr $h-$m?"m":"x"]
设置分钟。如果小时和分钟相同,请x
改用。string map /\ $p {rr/nrzmrann xrrr snnimrrrcnn vrrr wnnromrenrru}
/\ $p
等于"/ $p"
,所以我添加了第一个键(/
)。之后,我rr/nrzmrann xrrr snnimrrrcnn vrrr wnnromrenrru
用它的值替换每次出现的键。通常的地图是
/ o a o s o c o w o e o u o o o v o i o x o z o m { } r { } n {
}
(读为“替换/
为o
,替换a
为o
...替换m
为___
(应为空格)”)
我repace一个o
具有h
和其他与m
,m
,r
和n
只是为了shoren输出字符串(我更换了空间与其中的一个,也\n
有n
)。稍后我添加第一个元素,因此我可以使用h * 2代替h * 2 + 1来替换索引。(节省2个字符)
一些注意事项:
{}
。好的,这有点复杂,例如,您可以使用来转义空格\
,但此类详细信息已在其他地方进行了说明。key1 value1 key2 value2
好的,很多,但是它们很好并且工作与我以前的帖子(bash和perl)中的以前的变体相同。
这个版本比您在我的极客辅助时钟上找到的 版本更加模糊
var x='<div class="m"> M</div>',v='<div class="s"> s</div>',w=' '
,r=10,q,w=' ',y='<div class="h"> H</div>',f=new Object();function d(){
q=document.getElementById("asciiclock");var t=document.location.toString().match
(/[?]([0-9]+)/);if (t!=null) r=t[1]*1.0;a();b();}function m(e){r=e;a();}function
a(){f=[];for (var i=1;r>i;i++){var u=Math.round(Math.sqrt(Math.pow(r,2)-Math.pow
(r-i,2)));f[(2*r-i)+"x"+(r+u)]=w+".";f[(i)+"x"+(r+u)]=w+".";f[(2*r-i)+"x"+(r-u)]
=w+".";f[(i)+"x"+(r-u)]=w+".";f[(r+u)+"x"+(2*r-i)]=w+".";f[(r+u)+"x"+(i)]=w+".";
f[(r-u)+"x"+(2*r-i)]=w+".";f[(r-u)+"x"+(i)]=w+".";}for(var i=1;13>i;i++){f[Math.
round(r+r*Math.sin(Math.PI/6*i-Math.PI/2))+"x"+Math.round(r+r*Math.cos(Math.PI/6
*i-Math.PI/2))]='<div class="t">'+(i<10?w+i:i)+'</div>';}}function b(){var z='';
var s=new Date(), o=s.getMinutes()*1.0+1.0*s.getSeconds()/60,p=s.getHours()*1.0+
1.0*o/60,n=s.getSeconds()*1.0,k=s.getHours();if (k<10) k=w+k;var j=s.getMinutes(
);if (j<10) j=w+j;var h=s.getSeconds();if (h<10)h=w+h;var g=new Object();for(var
i=1;r*.78>=i;i++) {g[Math.round(r+i*Math.sin (Math.PI/30*o-Math.PI/2))+"x"+Math.
round(r+i*Math.cos(Math.PI/30*o-Math.PI/2))]=x;};for (var i=1;r*.62 >=i;i++) {g[
Math.round(r+i*Math.sin(Math.PI/6*p-Math.PI/2))+"x"+Math.round(r+i*Math.cos(Math
.PI/6*p-Math.PI/2))]=y;};g[Math.round(r+.87*r*Math.sin(Math.PI/30*n-Math.PI/2))+
"x"+Math.round(r+.87*r*Math.cos(Math.PI/30*n-Math.PI/2))]=v;for (var i=0;2*r>=i;
i++){for(var l=0;2*r>=l;l++){if((i==r)&&(l==i)){z+=w+'<div class="t">'+['.','+',
'*','o','O'][n%5]+'</div>';}else if(f[i+"x"+l]!=undefined){z+=f[i+"x"+l]}else if
(g[i+"x"+l]!=undefined){z+=g[i+"x"+l];}else if(l==2*r){if(i==0){z+=w+'<div clas'
+'s="t">'+k+'</div>';}else if(i==l){z+=w+'<div class="t">'+h+'</div>';}else{z+=w
+w;};}else if(l==0){if(i==2*r){z+='<div class="t">'+j+'</div>';}else if(i==0){z=
'<div class="r">S</div>'+w;}else{z+=w+w}}else{z+=w+w}};z+='<br />';};q.innerHTML
=z;window.setTimeout(b,1000-new Date().getMilliseconds());};function c(){window.
setTimeout(b,0);q.innerHTML=w+q.innerHTML.substring (22);q.setAttribute('style',
'display:none');q.setAttribute('style',null)};window.onload=d;
.asciiclock { margin: 3em 0px 0px 0px;padding: 2px 4px 2px 3px; font-size: .5em;
display:inline-block;font-family:mono,monospace,courier;background:rgba(0,0,0,.7
);color: #888;}.asciiclock div{ display:inline-block;font-weight:bold;}.h{color:
#46F;}.m{color:#0F0;}.s{color:#0FF;}.r{color:#000;background:#aaa;}.t{color:#aaa
;}pre{display:inline-block;}
<head><title>Ascii-clock</title><script type="text/javascript" src="ascii-clock.js"
></script><link rel="stylesheet" href="ascii-clock.css" type="text/css"><style
type="text/css">body{margin:0;padding:0;background:#000;}.asciiclock{margin:0}
</style></head><body><div id="asciiclock" class="asciiclock"></div></body>
from time import*
from math import*
g=[[' ']*61 for _ in[0]*31]
while 1:
t=localtime()
for x in range(60):a=pi*x/30-pi/2;g[15+int(15*sin(a))][30+int(30*cos(a))]='m'if x==t.tm_min else'h'if x==t.tm_hour%12*5 else'-'if x%5 else'#'
for r in g:print''.join(r)
样本输出:
#
- - - - - -
- -
- h # -
- -
- -
m -
# #
- -
- -
- -
- -
# #
- -
- -
- -
- -
# #
- -
- -
- -
- # # -
- -
- - - - - -
#
M=Math
P=M::PI
x=->n,m=60,r,c{$><<"^[[%d;%dH%s\n"%[M.sin(n*P*2/m-P/2)*r+12,M.cos(n*P*2/m-P/2)*r*2+24,c]}
while t=Time.now
$><<"^[[2J"
1.upto(12){|i|x[i,12,11,i]}
x[t.hour*5+t.min/12,8,?H]
x[t.min,9,?M]
x[t.sec,10,?S]
sleep 0.1
end
(注意:^[
是一个字符。)
样品运行(21:19:33):
12
11 1
10 2
H
9 3
M
8 4
7 S 5
6
(较小的尺寸,较低的精度,没有秒,相同的半径,可怕的闪烁。)
x=->n,m=60,c{$><<"^[[%d;%dH%s\n"%[Math.sin(n*6.3/m-1.6)*8+9,Math.cos(n*6.3/m-1.6)*8+9,c]}
while t=Time.now
$><<"^[[2J"
1.upto(12){|i|x[i,12,i]}
x[t.hour*5+t.min/12,?H]
x[t.min,?M]
end
样品运行(21:19):
12 1
11
2
10
H 3
9
M
8
5
7 6
(受Johannes Kuhn的Tcl解决方案的启发。由于我仍然没有破译他的代码,所以不确定多少。)
while t=Time.now
puts"^[[2J k l a
j\tb
i\tc
h\td
g f e".tr((t.min/5+96).chr,?M).tr(((t.hour-1)%12+97).chr,?H).tr("a-l",?*)
end
样品运行(21:19):
* * *
* *
H M
* *
* * *
tr': can't convert Fixnum into String (TypeError)”? Now that you mentioned the error I dug for a version 1.8.7 and received the above error of that. Works fine on 1.9.2 and 1.9.3. Seems that
?M ” 在较旧的版本中被解释为Fixnum,直到后来才更改为String。
397 - 20% = 317.6 characters
我的第一次迭代。我对此不太满意,但是它确实有效并且确实以非常清晰的方式显示了时间。
<canvas id=c width=198 height=198></canvas><script>c=document.getElementById("c")
.getContext("2d");c.r=c.rotate;c.c=c.clearRect;c.translate(99,99);for(i=0;i<60;i++)
{c.fillRect(89,-1,i%5?3:9,5);c.r(p=Math.PI/30);}setInterval(function(){n=new Date();
h=n.getHours()*5*p;c.beginPath();c.arc(0,0,86,0,7);c.fill();c.r(m=n.getMinutes()*p);
c.c(-2,-3,4,-80);c.r(h-m);c.c(-2,-3,4,-50);c.r(-h);},5);</script>
:Xmax/2→Xmax:Ymax/2→Ymax:-Xmax→Xmin:-Ymax→Ymin:Degree:15→H:20→M:18→S::Circle(0,0,30):For(X,1,12)::Text(28-int(cos(X*30)*25),46+int(sin(30*X)*25),X):End:{0,0,0}→LANG:While getKey=0::getTime→LTIME::If LTIME(3)≠LANG(3)/6:Line(0,0,sin(LANG(3))*S,cos(LANG(3))*S,0)::If LTIME(2)≠LANG(2)/6:Then:::Line(0,0,sin(LANG(2))*M,cos(LANG(2))*M,0):::Line(0,0,sin(LANG(1))*H,cos(LANG(1))*H,0)::End::"SET ANGS::LTIME(1)*30+LTIME(2)/2→LANG(1)::LTIME(2)*6→LANG(2)::LTIME(3)*6→LANG(3)::Line(0,0,sin(LANG(1))*H,cos(LANG(1))*H::Line(0,0,sin(LANG(2))*M,cos(LANG(2))*M::Line(0,0,sin(LANG(3))*S,cos(LANG(3))*S:End
它的输出非常漂亮和详细。
C,554字节,大约每秒更新一次。
#include <time.h>
#include <math.h>
int r=25,i,q,c,i,q,b[999];void v(float a,int f,int m){b[(r/2+(int)(sin(a)*f))*r+r/2+(int)(cos(a)*f)]=m;}void main(){float a,p=6.28,z=1.57,h,m,s;for(;;){time_t u=time(0);struct tm*l=localtime(&u);s=l->tm_sec;m=l->tm_min+s/60.;h=l->tm_hour+m/60.;system("@cls||clear");q=r*r;c=r/2;memset(b,32,q*4);for(i=0,a=p;a>0;a-=0.52,i++)v(a,c,i%3?46:i%6?124:45);v(0,0,79);v(p*s/60.-z,c-4,83);v(p*m/60.-z,c-5,77);v(p*h/12.-z,c-6,72);for(i=0;i<q;i++){c=b[i];putchar(c);if(i%r==r-1)putchar(10);}for(c=0;c<2000000;c++)hypot(3,.4);}}
结果:
|
. .
.
S .
H
- O -
M
.
.
. .
|