Class: Pixelflow::Canvas::MaskGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/pixelflow_canvas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(canvas) ⇒ MaskGenerator

Returns a new instance of MaskGenerator.



217
218
219
220
# File 'lib/pixelflow_canvas.rb', line 217

def initialize(canvas)
    @canvas = canvas
    @mask = [false] * canvas.width * canvas.height
end

Instance Attribute Details

#maskObject (readonly)

Returns the value of attribute mask.



222
223
224
# File 'lib/pixelflow_canvas.rb', line 222

def mask
  @mask
end

Instance Method Details

#add_color(r = nil, g = nil, b = nil) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/pixelflow_canvas.rb', line 224

def add_color(r = nil, g = nil, b = nil)
    offset = 0
    (0...@canvas.height).each do |y|
        (0...@canvas.width).each do |x|
            if @canvas.color_mode == :rgb
                if @canvas.get_pixel(x, y) == [r, g, b]
                    @mask[offset] = true
                end
            else
                if @canvas.get_pixel(x, y) == r
                    @mask[offset] = true
                end
            end
            offset += 1
        end
    end
end