Class: Amaze::Shape::Star

Inherits:
Amaze::Shape show all
Defined in:
lib/amaze/shape/star.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
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/amaze/shape/star.rb', line 4

def build_mask
  (0...size).each do |row|
    # top section
    on = row * 2 + 1
    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|
      # upper triangle
      mask[row, i] = switch
      # lower triangle
      mask[rows-1-row, i] = switch
    end
    
    # middle section
    on = columns - offset * 2 - row * 2
    off = (columns - on) / 2
    line_map = Array.new(off, false) + Array.new(on, true) + Array.new(off, false)
    line_map.each_with_index do |switch, i|
      # middle upper
      mask[row + size, i] = switch
      # middle lower
      mask[rows - 1 - size - row, i] = switch
    end
  end
end

#columnsObject



35
36
37
# File 'lib/amaze/shape/star.rb', line 35

def columns
  (size - 1) * 6 + 5 + offset * 2
end

#offsetObject



39
40
41
# File 'lib/amaze/shape/star.rb', line 39

def offset
  size.even? ? 0 : 1
end

#rowsObject



31
32
33
# File 'lib/amaze/shape/star.rb', line 31

def rows
  size * 4
end