class Branding::Pixel2x

Public Class Methods

load_strategy(pixels, height: 0, width: 0) { |self| ... } click to toggle source
# File lib/branding/pixel.rb, line 102
def self.load_strategy(pixels, height: 0, width: 0)
  matrix = Matrix.build(height, width) do |row, col|
    pixels[col + row*width]
  end

  (0..height).step(2) do |row|
    matrix.minor(row, 2, 0, width).transpose.to_a.each do |top, bottom|
      yield self.new(top.to_i, bottom.to_i)
    end
  end
end
new(top, bottom) click to toggle source
# File lib/branding/pixel.rb, line 114
def initialize(top, bottom)
  @top, @bot = top, bottom

  @top ||= 0x000000ff
  @bot ||= 0x000000ff
end

Public Instance Methods

to_s() click to toggle source
# File lib/branding/pixel.rb, line 125
def to_s
  if ANSI.clamped(@top) == ANSI.clamped(@bot)
    return "#{ANSI.bg(*ANSI.uint32_to_rgb(@top))} "
  end

  "#{ANSI.fg(*ANSI.uint32_to_rgb(@bot))}#{ANSI.bg(*ANSI.uint32_to_rgb(@top))}▄"
end
width() click to toggle source
# File lib/branding/pixel.rb, line 121
def width
  1
end