Class: GridGenerator::Skewb::ElementFactory
- Inherits:
-
Object
- Object
- GridGenerator::Skewb::ElementFactory
- Defined in:
- lib/grid_generator/skewb/element_factory.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#col_num ⇒ Object
readonly
Returns the value of attribute col_num.
-
#colour ⇒ Object
readonly
Returns the value of attribute colour.
-
#grid_x ⇒ Object
readonly
Returns the value of attribute grid_x.
-
#grid_y ⇒ Object
readonly
Returns the value of attribute grid_y.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#row_num ⇒ Object
readonly
Returns the value of attribute row_num.
-
#side_size ⇒ Object
readonly
Returns the value of attribute side_size.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(grid_x:, grid_y:, row_num:, col_num:, side_size:, units:, colour:, opacity:) ⇒ ElementFactory
constructor
A new instance of ElementFactory.
- #offset ⇒ Object
- #points ⇒ Object
Constructor Details
#initialize(grid_x:, grid_y:, row_num:, col_num:, side_size:, units:, colour:, opacity:) ⇒ ElementFactory
Returns a new instance of ElementFactory.
7 8 9 10 11 12 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 7 def initialize(grid_x:, grid_y:, row_num:, col_num:, side_size:, units:, colour:, opacity:) @grid_x, @grid_y = grid_x, grid_y @row_num, @col_num = row_num, col_num @side_size, @units = side_size, units @colour, @opacity = colour, opacity end |
Instance Attribute Details
#col_num ⇒ Object (readonly)
Returns the value of attribute col_num.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def col_num @col_num end |
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def colour @colour end |
#grid_x ⇒ Object (readonly)
Returns the value of attribute grid_x.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def grid_x @grid_x end |
#grid_y ⇒ Object (readonly)
Returns the value of attribute grid_y.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def grid_y @grid_y end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def opacity @opacity end |
#row_num ⇒ Object (readonly)
Returns the value of attribute row_num.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def row_num @row_num end |
#side_size ⇒ Object (readonly)
Returns the value of attribute side_size.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def side_size @side_size end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
14 15 16 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 14 def units @units end |
Instance Method Details
#build ⇒ Object
59 60 61 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 59 def build GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) end |
#offset ⇒ Object
16 17 18 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 16 def offset @offset ||= Matrix.column_vector([grid_x, grid_y]) end |
#points ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/grid_generator/skewb/element_factory.rb', line 20 def points _points = case [row_num, col_num] when [0, 0] # top left corner [ anchors[:top_left_corner], anchors[:top_middle], anchors[:left_middle] ] when [0, 1] # top right corner [ anchors[:top_middle], anchors[:top_right_corner], anchors[:right_middle] ] when [1, 0] # center [ anchors[:top_middle], anchors[:right_middle], anchors[:bottom_middle], anchors[:left_middle] ] when [2, 0] # bottom left corner [ anchors[:left_middle], anchors[:bottom_middle], anchors[:bottom_left_corner] ] when [2, 1] # bottom right corner [ anchors[:right_middle], anchors[:bottom_right_corner], anchors[:bottom_middle] ] else [] end _points.map { |p| p + offset } end |