バイナリクロック
Posted feedbacks - Python
pythonで素直に。timezoneの設定は、サマータイムがない国にとっては面倒なだけです。
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 | #!/usr/bin/python
#coding: utf-8
import datetime
# 横の文字数
cols = 6
# datatimeでJSTを使用する
class tz_jst(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=9)
def dst(self, dt):
return datetime.timedelta()
def tzname(self):
return 'JST'
# n: 表示する数字, digits: 表示する桁数, cols: 横の文字数
# one: 1のときに表示する文字, zero: 0のときに表示する文字, padding: paddingに使用する文字
def print_bin(n, digits, cols, one='■', zero='□', padding=' '):
s = ''
if cols > digits: s += padding * (cols - digits)
powers = [2**i for i in range(digits)]
powers.reverse()
# オーバーフロー分を切り捨てる
n = n % 2**digits
for x in powers:
s += one if n / x else zero
n %= x
print s
dt = datetime.datetime.now(tz_jst())
print_bin(dt.hour, 5, cols)
print_bin(dt.minute, 6, cols)
|

lunlumo #9282() [ Ruby ] Rating6/8=0.75
20:18の場合,例えば以下の様な出力をするイメージです。
出力例:
■□■□□
□■□□■□
see: Binary Clock Widget
Rating6/8=0.75-0+
[ reply ]