Created
October 22, 2011 06:56
-
-
Save mkeen/1305725 to your computer and use it in GitHub Desktop.
Let's Get Digital Challenge (Red Version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| $characters = [[[0,1,1,0], [1,0,0,1], [1,0,0,1], [0,0,0,0], [1,0,0,1], [1,0,0,1], [0,1,1,0]], [[0,0,0,0], [0,0,0,1], [0,0,0,1], [0,0,0,0], [0,0,0,1], [0,0,0,1], [0,0,0,0]], [[0,1,1,0], [0,0,0,1], [0,0,0,1], [0,1,1,0], [1,0,0,0], [1,0,0,0], [0,1,1,0]], [[0,1,1,0], [0,0,0,1], [0,0,0,1], [0,1,1,0], [0,0,0,1], [0,0,0,1], [0,1,1,0]], [[0,0,0,0], [1,0,0,1], [1,0,0,1], [0,1,1,0], [0,0,0,1], [0,0,0,1], [0,0,0,0]], [[0,1,1,0], [1,0,0,0], [1,0,0,0], [0,1,1,0], [0,0,0,1], [0,0,0,1], [0,1,1,0]], [[0,1,1,0], [1,0,0,0], [1,0,0,0], [0,1,1,0], [1,0,0,1], [1,0,0,1], [0,1,1,0]], [[0,1,1,0], [0,0,0,1], [0,0,0,1], [0,0,0,0], [0,0,0,1], [0,0,0,1], [0,0,0,0]], [[0,1,1,0], [1,0,0,1], [1,0,0,1], [0,1,1,0], [1,0,0,1], [1,0,0,1], [0,1,1,0]], [[0,1,1,0], [1,0,0,1], [1,0,0,1], [0,1,1,0], [0,0,0,1], [0,0,0,1], [0,1,1,0]]] | |
| class DigiChar | |
| attr_accessor :integer | |
| def initialize integer = nil | |
| @integer = integer | |
| end | |
| end | |
| class CharsContainer | |
| def self.add_digit digit, redraw = false | |
| @segments ||= [] | |
| @segments << DigiChar.new(digit) | |
| draw unless !redraw | |
| end | |
| def self.set_digit index, value, redraw = true | |
| @segments[index] = DigiChar.new(value) | |
| draw unless !redraw | |
| end | |
| def self.draw | |
| print "\e[2J\e[f\n\n" | |
| 7.times do |time| | |
| seg_count = 0 | |
| @segments.each do |segment| | |
| $characters[segment.integer][time].each do |char_column| | |
| if char_column == 1 and ((segment.integer != 0) || (seg_count > 0)) | |
| print "\e[31m@\e[0m " | |
| else | |
| print " " | |
| end | |
| end | |
| if (time == 2 or time == 4) and (seg_count == 1) and $blink_on | |
| print " \e[31m|\e[0m " | |
| else | |
| print " " | |
| end | |
| seg_count += 1 | |
| end | |
| print "\n" | |
| end | |
| $stdout.flush | |
| end | |
| end | |
| clock = Thread.new do | |
| 4.times do | |
| CharsContainer.add_digit(0, true) | |
| end | |
| loop do | |
| $time = Time.new.strftime("%I%M") | |
| 4.times do |time| | |
| CharsContainer.set_digit time, Time.new.strftime("%I%M")[time].to_i | |
| end | |
| $blink_on = !$blink_on | |
| CharsContainer.draw | |
| sleep 0.5 | |
| end | |
| end.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment