Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Created December 18, 2009 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeroenvandijk/259360 to your computer and use it in GitHub Desktop.
Save jeroenvandijk/259360 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module Chars
def scale(chars, scale)
print_chars scale_vertically(scale_horizontally(chars, scale), scale)
end
private
def chars
@chars ||= [
[
" |",
" |",
" |",
" |",
" |"
],
[
" - ",
" |",
" - ",
"| ",
" _ "
],
[
" - ",
" |",
" - ",
" |",
" _ "
]
]
end
def char(i)
chars[i - 1]
end
def scale_horizontally(chars, scale)
chars.map do |row|
row.map do |cell|
[0, [1] * scale, 2].flatten.map { |i| cell[i] }
end
end
end
def scale_vertically(chars, scale)
chars.map do |row|
[0, [1] * scale, 2, [3] * scale, 4].flatten.map { |i| row[i] }
end
end
def print_chars(chars)
puts chars.map { |row| row.map{ |col| col.join } }.join("\n")
end
end
unless @loaded
@loaded = true
require 'rubygems'
require 'boson'
require 'boson/runners/bin_runner'
# Boson.commands << Char
Boson::Repo
# load_library(Chars, Chars.public_methods)
Boson::BinRunner.start
Boson::Manager.load(Chars, :commands => Chars.public_methods)
end
# include Chars
#
# chars = [1, 2, 3].map { |x| char(x).map { |row| row.split("") } }
# scale(chars, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment