Skip to content

Instantly share code, notes, and snippets.

@TomTriple
Last active December 13, 2015 23:49
Show Gist options
  • Save TomTriple/4994238 to your computer and use it in GitHub Desktop.
Save TomTriple/4994238 to your computer and use it in GitHub Desktop.
class ConsoleImage
def initialize(m, n)
@m = m
@n = n
@colors = Array.new(m * n)
clear
end
def clear
@colors.fill "0"
end
def light(x, y, color)
@colors[(x - 1) * @n + y - 1] = color
end
def to_s
lines = ""
@colors.each_slice(@m) {|row| lines << row.reduce("") {|acc, it| acc << it } + "\n"}
lines
end
end
# encoding: utf-8
$:.unshift File.dirname(__FILE__)
require "console_image"
i = ConsoleImage.new(5, 3)
i.light(5, 3, "1")
i.light(1, 5, "1")
i.light(1, 1, "1")
i.light(3, 5, "1")
puts i
i.clear
puts "-----"
puts i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment