Class: Theseus::TriangleMask
- Inherits:
-
Object
- Object
- Theseus::TriangleMask
- Defined in:
- lib/theseus/mask.rb
Overview
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#[](x, y) ⇒ Object
Returns the
true/falsevalue for the corresponding cell in the grid. -
#initialize(height) ⇒ TriangleMask
constructor
Returns a new TriangleMask instance with the given height.
Constructor Details
#initialize(height) ⇒ TriangleMask
Returns a new TriangleMask instance with the given height. The width will always be 2h+1 (where h is the height).
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/theseus/mask.rb', line 76 def initialize(height) @height = height @width = @height * 2 + 1 @grid = Array.new(@height) do |y| run = y * 2 + 1 from = @height - y to = from + run - 1 Array.new(@width) do |x| (x >= from && x <= to) ? true : false end end end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
72 73 74 |
# File 'lib/theseus/mask.rb', line 72 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
72 73 74 |
# File 'lib/theseus/mask.rb', line 72 def width @width end |
Instance Method Details
#[](x, y) ⇒ Object
Returns the true/false value for the corresponding cell in the grid.
90 91 92 |
# File 'lib/theseus/mask.rb', line 90 def [](x,y) @grid[y][x] end |