Class: Pixelflow::Canvas::MaskGenerator
- Inherits:
-
Object
- Object
- Pixelflow::Canvas::MaskGenerator
- Defined in:
- lib/pixelflow_canvas.rb
Instance Attribute Summary collapse
-
#mask ⇒ Object
readonly
Returns the value of attribute mask.
Instance Method Summary collapse
- #add_color(r = nil, g = nil, b = nil) ⇒ Object
-
#initialize(canvas) ⇒ MaskGenerator
constructor
A new instance of MaskGenerator.
Constructor Details
#initialize(canvas) ⇒ MaskGenerator
Returns a new instance of MaskGenerator.
173 174 175 176 |
# File 'lib/pixelflow_canvas.rb', line 173 def initialize(canvas) @canvas = canvas @mask = [false] * canvas.width * canvas.height end |
Instance Attribute Details
#mask ⇒ Object (readonly)
Returns the value of attribute mask.
178 179 180 |
# File 'lib/pixelflow_canvas.rb', line 178 def mask @mask end |
Instance Method Details
#add_color(r = nil, g = nil, b = nil) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/pixelflow_canvas.rb', line 180 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 |