Newer
Older
Ruby / text.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

y = Time.now.year

def play(sound)
  spawn "ogg123 -q "+sound
end
def next1sec(sec)
  while sec == Time.now.sec
    sleep 0.03		# 秒が変わるまで待機する
  end
  Time.now.sec		# 新しい秒を返しておく(次に使う)
end

while y == Time.now.year # 年が同じ間繰り返す
  now = Time.now
  sec = now.sec
  just = now+60		# 1分後
  jh = just.hour	# 1分後の時
  jm = just.min		# 1分後の分
  while Time.now.min != jm
    sec = next1sec(sec)	# 秒の区切りまで待つ
    printf("%s\r", Time.now)	# \r は行頭に戻る
    if sec%300 == 0	# 30で割り切れる0秒か30秒なら
      play("po.ogg")	# 「ポーン♪」
    elsif sec%30 == 20	# 余りが20なら30秒区切りの10秒前
      play("kotsu.ogg")
      if		# 次の分の予告
        printf("只今から%d時%d分ちょうどをお知らせします\n", jh, jm)
      end
    elsif sec%30 > 26	# 3秒前の「プ」
      play("pu.ogg")
    else
      play("kotsu.ogg")	# 特に何もないときは「コツ」
    end
  end
end

lost = Time.now.year

while true
  new = Time.now
  sleep(0.0001)
  if new == lost
    puts(<<EOF)
      ∧_,,∧
. /\. (`・ω・´) /ヽあけおめ!
 | ● ⊂   ⊃ ● |    あけおめ!
 ヽ/ /   く \ /
    (ノ⌒ヽ)

     ︵/\)\)\ /\__
   ︵\         \  /__
   \ )\    (    /  /__
  \︶\  \   )  /     /
   |------------------|
   |------------------|
  {|------------------|} 
  {{                  }}
   {\                /}
     \    ______    /
      \  \__/  /
        \______/

EOF
system"banner Happe new yaer!"
system"ruby she.rb"
  end
end