Newer
Older
Ruby / 2023.rb
@HIROSE Yuuji HIROSE Yuuji on 31 Dec 2022 931 bytes 2022-12-31 21:24:28
#!/usr/bin/env ruby
class NY
  def initialize
    @digit = []
    0.upto(9) do |i|
      open("|kbanner|sed 's/^    //;s/    $//'", "w+") do |k|
        k.printf("%d", i)
        k.close_write
        @digit << k.read.split("\n")
      end
    end
    @rows = @digit[0].length
  end
  def dispDigits(str, color=nil)
    disp = ""
    0.upto(@rows-1) do |row|
      str.each_char do |col|
	disp += @digit[col.to_i][row]
      end
      disp += "\n"
    end
    p color
    color and printf("\e[%dm", color)
    printf("\e[2J\e[1;1H%s\e[m", disp)
  end
  def start(goal = "23:59:50")
    last = ""
    while Time.now.strftime("%T") != goal
      sec = (Time.mktime(2023,1,1)-Time.now).to_i.to_s
      if last == sec
        sleep 0.1
      else
	dispDigits(sec)
        last = sec
      end
    end
  end
end
#print digit[9][0].length; exit
NY.new.start
NY.new.start("00:00:00")
#NY.new.start("20:55:00")
system "display ny2023.jpg"