Class: Amaze::Shape::Triangle

Inherits:
Amaze::Shape show all
Defined in:
lib/amaze/shape/triangle.rb

Instance Attribute Summary

Attributes inherited from Amaze::Shape

#size

Instance Method Summary collapse

Methods inherited from Amaze::Shape

#create_mask, #initialize, #mask

Constructor Details

This class inherits a constructor from Amaze::Shape

Instance Method Details

#build_maskObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/amaze/shape/triangle.rb', line 4

def build_mask
  (0...rows).each do |row|
    # How many cells are on
    on = (row+1) * 2 - 1
    # How many cells are off
    off = (columns - on) / 2
    # Build a line: #off cells, #on cells, #off cells
    line_map = Array.new(off, false) + Array.new(on, true) + Array.new(off, false)
    line_map.each_with_index do |switch, i|
      mask[row, i] = switch
    end
  end
end

#columnsObject



22
23
24
# File 'lib/amaze/shape/triangle.rb', line 22

def columns
  (rows+1)/2 * 4 - 1
end

#rowsObject



18
19
20
# File 'lib/amaze/shape/triangle.rb', line 18

def rows
  size
end