Class: Branding::Pixel2x
Instance Attribute Summary
Attributes inherited from Pixel
#uint32
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Pixel
#==, #a, #b, #g, #inspect, #r, rgb, #to_i, #to_rgb, #to_rgba
Constructor Details
#initialize(top, bottom) ⇒ Pixel2x
Returns a new instance of Pixel2x.
114
115
116
117
118
119
|
# File 'lib/branding/pixel.rb', line 114
def initialize(top, bottom)
@top, @bot = top, bottom
@top ||= 0x000000ff
@bot ||= 0x000000ff
end
|
Class Method Details
.load_strategy(pixels, height: 0, width: 0) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# 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
|
Instance Method Details
#to_s ⇒ Object
125
126
127
128
129
130
131
|
# 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 ⇒ Object
121
122
123
|
# File 'lib/branding/pixel.rb', line 121
def width
1
end
|