grid_generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/grid_generator.gemspec +36 -0
- data/lib/grid_generator/arrows/arrow.rb +29 -0
- data/lib/grid_generator/arrows/diagonal_down_arrow.rb +107 -0
- data/lib/grid_generator/arrows/diagonal_up_arrow.rb +108 -0
- data/lib/grid_generator/arrows/horizontal_arrow.rb +108 -0
- data/lib/grid_generator/arrows/vertical_arrow.rb +108 -0
- data/lib/grid_generator/base_element.rb +30 -0
- data/lib/grid_generator/cubic/bordered_grid.rb +129 -0
- data/lib/grid_generator/cubic/facing_grid.rb +109 -0
- data/lib/grid_generator/cubic/facing_square_factory.rb +38 -0
- data/lib/grid_generator/cubic/front_grid.rb +27 -0
- data/lib/grid_generator/cubic/grid.rb +146 -0
- data/lib/grid_generator/cubic/iso_view.rb +30 -0
- data/lib/grid_generator/cubic/right_grid.rb +27 -0
- data/lib/grid_generator/cubic/square_factory.rb +46 -0
- data/lib/grid_generator/cubic/top_grid.rb +27 -0
- data/lib/grid_generator/face_parser.rb +43 -0
- data/lib/grid_generator/megaminx/common.rb +94 -0
- data/lib/grid_generator/megaminx/element_factory.rb +52 -0
- data/lib/grid_generator/megaminx/face.rb +79 -0
- data/lib/grid_generator/pyraminx/grid.rb +83 -0
- data/lib/grid_generator/pyraminx/triangle_factory.rb +45 -0
- data/lib/grid_generator/skewb/left_element_factory.rb +90 -0
- data/lib/grid_generator/skewb/left_skewb_grid.rb +43 -0
- data/lib/grid_generator/skewb/right_element_factory.rb +90 -0
- data/lib/grid_generator/skewb/right_skewb_grid.rb +43 -0
- data/lib/grid_generator/skewb/skewb_grid.rb +62 -0
- data/lib/grid_generator/skewb/top_element_factory.rb +90 -0
- data/lib/grid_generator/skewb/top_skewb_grid.rb +43 -0
- data/lib/grid_generator/square_one/element.rb +60 -0
- data/lib/grid_generator/square_one/element_factory.rb +89 -0
- data/lib/grid_generator/square_one/face.rb +82 -0
- data/lib/grid_generator/square_one_face_parser.rb +61 -0
- data/lib/grid_generator/version.rb +5 -0
- data/lib/grid_generator.rb +107 -0
- data/sig/grid_generator.rbs +4 -0
- metadata +103 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require './lib/grid_generator/cubic/grid'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module Cubic
|
5
|
+
class TopGrid < Cubic::Grid
|
6
|
+
def width_unit
|
7
|
+
@width_unit ||= Matrix.column_vector([units, units/2])
|
8
|
+
end
|
9
|
+
|
10
|
+
def height_unit
|
11
|
+
@height_unit ||= Matrix.column_vector([-units, units/2])
|
12
|
+
end
|
13
|
+
|
14
|
+
def offset_unit
|
15
|
+
@offset_unit ||= Matrix.column_vector([units,0])
|
16
|
+
end
|
17
|
+
|
18
|
+
def line_offset_amount
|
19
|
+
height
|
20
|
+
end
|
21
|
+
|
22
|
+
def square_offset_amount
|
23
|
+
height - 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GridGenerator
|
2
|
+
class FaceParser
|
3
|
+
COLOURS = {
|
4
|
+
'w' => '#ffffff',
|
5
|
+
'y' => '#ffff00',
|
6
|
+
'b' => '#0000ff',
|
7
|
+
'g' => '#00ff00',
|
8
|
+
'r' => '#ff0000',
|
9
|
+
'o' => '#ffb000',
|
10
|
+
'gr' => '#808080',
|
11
|
+
'br' => '#804000',
|
12
|
+
's' => '#8080ff',
|
13
|
+
'l' => '#80ff80',
|
14
|
+
'p' => '#800080',
|
15
|
+
'pi' => '#ff8080'
|
16
|
+
}
|
17
|
+
|
18
|
+
OPACITY = {
|
19
|
+
full: 1,
|
20
|
+
faded: 0.4
|
21
|
+
}
|
22
|
+
|
23
|
+
def initialize(string)
|
24
|
+
@string = string
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :string
|
28
|
+
|
29
|
+
def to_a
|
30
|
+
string.split(/\\n/).map do |line|
|
31
|
+
line.split(',').map(&:strip).map do |col|
|
32
|
+
if col == '-'
|
33
|
+
nil
|
34
|
+
else
|
35
|
+
colour = COLOURS[col.downcase]
|
36
|
+
opacity = OPACITY[(/[[:upper:]]/.match(col) ? :full : :faded)]
|
37
|
+
{ colour: colour, opacity: opacity }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
module GridGenerator
|
3
|
+
module Megaminx
|
4
|
+
module Common
|
5
|
+
ROTATION_STEP = 2 * Math::PI / 5
|
6
|
+
|
7
|
+
ROTATION_MATRIX = Proc.new do |theta|
|
8
|
+
Matrix[
|
9
|
+
[Math.cos(theta), -1*Math.sin(theta)],
|
10
|
+
[Math.sin(theta), Math.cos(theta)]
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
ROTATION_MATRICES = Array.new(5) do |i|
|
15
|
+
ROTATION_MATRIX.call(ROTATION_STEP * i)
|
16
|
+
end
|
17
|
+
|
18
|
+
def rotation_offset_matrix
|
19
|
+
@rotation_offset_matrix ||= ROTATION_MATRIX.call(rotation_offset)
|
20
|
+
end
|
21
|
+
|
22
|
+
def rotation_point
|
23
|
+
@rotation_point ||= Matrix.column_vector([x+2*units, y+2*units])
|
24
|
+
end
|
25
|
+
|
26
|
+
def rotate(matrix, point)
|
27
|
+
(matrix * (point - rotation_point)) + rotation_point
|
28
|
+
end
|
29
|
+
|
30
|
+
# line
|
31
|
+
|
32
|
+
def intersection(a,b,c,d)
|
33
|
+
x1 = a[0,0]
|
34
|
+
y1 = a[1,0]
|
35
|
+
x2 = b[0,0]
|
36
|
+
y2 = b[1,0]
|
37
|
+
x3 = c[0,0]
|
38
|
+
y3 = c[1,0]
|
39
|
+
x4 = d[0,0]
|
40
|
+
y4 = d[1,0]
|
41
|
+
|
42
|
+
px_numerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)
|
43
|
+
px_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
44
|
+
|
45
|
+
py_numerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)
|
46
|
+
py_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
47
|
+
|
48
|
+
px = px_numerator / px_denominator
|
49
|
+
py = py_numerator / py_denominator
|
50
|
+
|
51
|
+
Matrix.column_vector([px, py])
|
52
|
+
end
|
53
|
+
|
54
|
+
# points
|
55
|
+
|
56
|
+
def top_outer_corner
|
57
|
+
@top_outer_corner ||= rotate(rotation_offset_matrix, Matrix.column_vector([x+2*units,y]))
|
58
|
+
end
|
59
|
+
|
60
|
+
def top_outer_edge
|
61
|
+
point_a, point_b = outer_corners.first(2)
|
62
|
+
@top_outer_edge = (point_a + point_b) / 2
|
63
|
+
end
|
64
|
+
|
65
|
+
def top_inner_corner
|
66
|
+
intersection(outer_edges[4], outer_edges[1], outer_edges[3], outer_edges[0])
|
67
|
+
end
|
68
|
+
|
69
|
+
def outer_corners
|
70
|
+
@outer_corners ||= ROTATION_MATRICES.map do |matrix|
|
71
|
+
rotate(matrix, top_outer_corner)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def outer_edges
|
76
|
+
@outer_edges ||= ROTATION_MATRICES.map do |matrix|
|
77
|
+
rotate(matrix, top_outer_edge)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def inner_corners
|
82
|
+
@inner_corners ||= ROTATION_MATRICES.map do |matrix|
|
83
|
+
rotate(matrix, top_inner_corner)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def outer_edges_ordered_by_evens_then_odds
|
88
|
+
evens = outer_edges.select.with_index { |_,i| i % 2 == 0 }
|
89
|
+
odds = outer_edges.select.with_index { |_,i| i % 2 == 1 }
|
90
|
+
evens + odds
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require './lib/grid_generator/base_element'
|
2
|
+
require './lib/grid_generator/megaminx/common'
|
3
|
+
|
4
|
+
module GridGenerator
|
5
|
+
module Megaminx
|
6
|
+
class ElementFactory
|
7
|
+
include GridGenerator::Megaminx::Common
|
8
|
+
|
9
|
+
CENTER_INDEX = 0
|
10
|
+
EDGE_INDEX = 1
|
11
|
+
CORNER_INDEX = 2
|
12
|
+
|
13
|
+
def initialize(x: , y:, row_index:, element_index:, units:, colour:, opacity:, rotation_offset: 0)
|
14
|
+
@x, @y = x, y
|
15
|
+
@row_index = row_index
|
16
|
+
@element_index = element_index
|
17
|
+
@units = units
|
18
|
+
@colour = colour
|
19
|
+
@opacity = opacity
|
20
|
+
@rotation_offset = rotation_offset
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :x, :y, :row_index, :element_index, :units, :colour, :opacity, :rotation_offset
|
24
|
+
|
25
|
+
def points
|
26
|
+
case row_index
|
27
|
+
when CENTER_INDEX
|
28
|
+
inner_corners
|
29
|
+
when EDGE_INDEX
|
30
|
+
[
|
31
|
+
outer_edges[element_index],
|
32
|
+
inner_corners[(element_index+1) % 5],
|
33
|
+
inner_corners[element_index],
|
34
|
+
]
|
35
|
+
when CORNER_INDEX
|
36
|
+
[
|
37
|
+
outer_corners[element_index],
|
38
|
+
outer_edges[element_index],
|
39
|
+
inner_corners[element_index],
|
40
|
+
outer_edges[(element_index-1) % 5],
|
41
|
+
]
|
42
|
+
else
|
43
|
+
raise ArgumentError, "unknown row #{row_index}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def build
|
48
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require './lib/grid_generator/face_parser'
|
2
|
+
require './lib/grid_generator/megaminx/common'
|
3
|
+
require './lib/grid_generator/megaminx/element_factory'
|
4
|
+
|
5
|
+
module GridGenerator
|
6
|
+
module Megaminx
|
7
|
+
class Face
|
8
|
+
include GridGenerator::Megaminx::Common
|
9
|
+
|
10
|
+
def initialize(x:, y: , units: , elements: , rotation_offset: 0, label: nil)
|
11
|
+
@x, @y = x, y
|
12
|
+
@units = units
|
13
|
+
@elements = FaceParser.new(elements).to_a
|
14
|
+
@rotation_offset = rotation_offset
|
15
|
+
@label = label
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :x, :y, :units, :elements, :rotation_offset, :label
|
19
|
+
|
20
|
+
# outline
|
21
|
+
|
22
|
+
def outline_string
|
23
|
+
outer_corners.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
24
|
+
end
|
25
|
+
|
26
|
+
def inner_string
|
27
|
+
inner_corners.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
28
|
+
end
|
29
|
+
|
30
|
+
def inline_string
|
31
|
+
outer_edges_ordered_by_evens_then_odds.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
32
|
+
end
|
33
|
+
|
34
|
+
# elements
|
35
|
+
|
36
|
+
def element_shapes
|
37
|
+
elements.each_with_index.map do |row, row_index|
|
38
|
+
row.each_with_index.map do |element, element_index|
|
39
|
+
GridGenerator::Megaminx::ElementFactory.new(
|
40
|
+
x: x,
|
41
|
+
y: y,
|
42
|
+
row_index: row_index,
|
43
|
+
element_index: element_index,
|
44
|
+
units: units,
|
45
|
+
colour: element[:colour],
|
46
|
+
opacity: element[:opacity],
|
47
|
+
rotation_offset: rotation_offset
|
48
|
+
).build if element
|
49
|
+
end
|
50
|
+
end.flatten.compact
|
51
|
+
end
|
52
|
+
|
53
|
+
# label methods
|
54
|
+
|
55
|
+
def label_position
|
56
|
+
x = rotation_point[0,0] - units*0.3
|
57
|
+
y = rotation_point[1,0] + units*0.4
|
58
|
+
{
|
59
|
+
x: x.round,
|
60
|
+
y: y.round
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def label_size
|
65
|
+
units
|
66
|
+
end
|
67
|
+
|
68
|
+
def as_json
|
69
|
+
{
|
70
|
+
"outline_string" => outline_string,
|
71
|
+
"inline_string" => inline_string,
|
72
|
+
"element_shapes" => element_shapes.as_json,
|
73
|
+
"label_position" => label_position,
|
74
|
+
"label_size" => label_size
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require './lib/grid_generator/pyraminx/triangle_factory'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module Pyraminx
|
5
|
+
class Grid
|
6
|
+
def initialize(x: ,y:, size: ,units: ,elements:)
|
7
|
+
@x, @y = x, y
|
8
|
+
@size = size
|
9
|
+
@units = units
|
10
|
+
@elements = elements
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :x, :y, :size, :units, :elements
|
14
|
+
|
15
|
+
def shape_points
|
16
|
+
[
|
17
|
+
[ x+size*units, y ],
|
18
|
+
[ x+2*size*units, y+size*units ],
|
19
|
+
[ x+size*units, y+2*size*units ],
|
20
|
+
[ x, y+size*units ]
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def shape_points_string
|
25
|
+
shape_points.map { |x,y| [x,y].join(',') }.join(' ')
|
26
|
+
end
|
27
|
+
|
28
|
+
def vertical_line_points
|
29
|
+
Array.new((2*size)-1) do |i|
|
30
|
+
{
|
31
|
+
"x1" => x+((i+1)-size).abs*units,
|
32
|
+
"y1" => y+(i+1)*units,
|
33
|
+
"x2" => x+((((i+1)-size).abs*-1)+2*size)*units,
|
34
|
+
"y2" => y+(i+1)*units
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def diagonal_down_line_points
|
40
|
+
Array.new(size-1) do |i|
|
41
|
+
{
|
42
|
+
"x1" => x+((i-1).abs + 1)*units,
|
43
|
+
"y1" => y+(i+1)*units,
|
44
|
+
"x2" => x+((i-1).abs + 1 + size)*units,
|
45
|
+
"y2" => y+(i+1+size)*units
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def diagonal_up_line_points
|
51
|
+
Array.new(size-1) do |i|
|
52
|
+
{
|
53
|
+
"x1" => x+(i+1)*units,
|
54
|
+
"y1" => y+(i+1+size)*units,
|
55
|
+
"x2" => x+(i+1+size)*units,
|
56
|
+
"y2" => y+(i+1)*units
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def element_shapes
|
62
|
+
elements.map do |row|
|
63
|
+
row.map do |element|
|
64
|
+
if element
|
65
|
+
GridGenerator::Pyraminx::TriangleFactory.new(x: x, y: y, units: units, direction: element[:direction], colour: element[:colour], opacity: element[:opacity]).build
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end.flatten.compact
|
71
|
+
end
|
72
|
+
|
73
|
+
def as_json
|
74
|
+
{
|
75
|
+
"vertical_line_points" => vertical_line_points,
|
76
|
+
"diagonal_down_line_points" => diagonal_down_line_points,
|
77
|
+
"diagonal_up_line_points" => diagonal_up_line_points,
|
78
|
+
"element_shapes" => element_shapes.map(&:as_json)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require './lib/grid_generator/base_element'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module Pyraminx
|
5
|
+
class TriangleFactory
|
6
|
+
def initialize(x:, y:, units:, direction:, colour:, opacity:)
|
7
|
+
@x, @y = x, y
|
8
|
+
@units = units
|
9
|
+
@direction = direction
|
10
|
+
@colour = colour
|
11
|
+
@opacity = opacity
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :x, :y, :units, :direction, :colour, :opacity
|
15
|
+
|
16
|
+
def up_points
|
17
|
+
[
|
18
|
+
Matrix.column_vector([ x+units, y ]),
|
19
|
+
Matrix.column_vector([ x+2*units, y+units ]),
|
20
|
+
Matrix.column_vector([ x, y+units ])
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def down_points
|
25
|
+
[
|
26
|
+
Matrix.column_vector([ x+units, y+units ]),
|
27
|
+
Matrix.column_vector([ x+2*units, y ]),
|
28
|
+
Matrix.column_vector([ x, y ])
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def points
|
33
|
+
if direction == :up
|
34
|
+
up_points
|
35
|
+
else
|
36
|
+
down_points
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def build
|
41
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module GridGenerator
|
2
|
+
module Skewb
|
3
|
+
class LeftElementFactory
|
4
|
+
def initialize(grid_x:, grid_y:, row_num:, col_num:, side_size:, units:, colour:, opacity:)
|
5
|
+
@grid_x, @grid_y = grid_x, grid_y
|
6
|
+
@row_num, @col_num = row_num, col_num
|
7
|
+
@side_size, @units = side_size, units
|
8
|
+
@colour, @opacity = colour, opacity
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :grid_x, :grid_y, :row_num, :col_num, :side_size, :units, :colour, :opacity
|
12
|
+
|
13
|
+
def x
|
14
|
+
@x ||= case [row_num, col_num]
|
15
|
+
when [0, 0] # Left Up
|
16
|
+
grid_x
|
17
|
+
when [0, side_size] # Left Front
|
18
|
+
grid_x+(side_size-1)*2*units
|
19
|
+
when [side_size, 0] # Left Left
|
20
|
+
grid_x
|
21
|
+
when [side_size, side_size] # Left Down
|
22
|
+
grid_x+(side_size-1)*2*units
|
23
|
+
when [(side_size/2),(side_size/2)] # Left Center
|
24
|
+
grid_x
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def y
|
31
|
+
@y ||= case [row_num, col_num]
|
32
|
+
when [0, 0] # Left Up
|
33
|
+
grid_y
|
34
|
+
when [0, side_size] # Left Front
|
35
|
+
grid_y+(side_size-1)*units
|
36
|
+
when [side_size, 0] # Left Left
|
37
|
+
grid_y+(side_size-1)*2*units
|
38
|
+
when [side_size, side_size] # Left Down
|
39
|
+
grid_y+(side_size)*2*units
|
40
|
+
when [(side_size/2),(side_size/2)] # Left Center
|
41
|
+
grid_y+(side_size/2)*units
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def points
|
48
|
+
case [row_num, col_num]
|
49
|
+
when [0, 0] # Left Up
|
50
|
+
[
|
51
|
+
[ x, y ],
|
52
|
+
[ x+2*units, y+units ],
|
53
|
+
[ x, y+2*units ]
|
54
|
+
]
|
55
|
+
when [0, side_size] # Left Front
|
56
|
+
[
|
57
|
+
[ x, y ],
|
58
|
+
[ x+2*units, y+units ],
|
59
|
+
[ x+2*units, y+3*units ]
|
60
|
+
]
|
61
|
+
when [side_size, 0] # Left Left
|
62
|
+
[
|
63
|
+
[ x, y ],
|
64
|
+
[ x+2*units, y+3*units ],
|
65
|
+
[ x, y+2*units ]
|
66
|
+
]
|
67
|
+
when [side_size, side_size] # Left Down
|
68
|
+
[
|
69
|
+
[ x+2*units, y ],
|
70
|
+
[ x+2*units, y+2*units ],
|
71
|
+
[ x, y+units ]
|
72
|
+
]
|
73
|
+
when [(side_size/2), (side_size/2)] # Left Center
|
74
|
+
[
|
75
|
+
[ x+2*units, y ],
|
76
|
+
[ x+4*units, y+3*units ],
|
77
|
+
[ x+2*units, y+4*units ],
|
78
|
+
[ x, y+units ]
|
79
|
+
]
|
80
|
+
else
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def build
|
86
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require './lib/grid_generator/skewb/skewb_grid.rb'
|
2
|
+
require './lib/grid_generator/skewb/left_element_factory.rb'
|
3
|
+
|
4
|
+
module GridGenerator
|
5
|
+
module Skewb
|
6
|
+
class LeftSkewbGrid < Skewb::SkewbGrid
|
7
|
+
def factory_class
|
8
|
+
GridGenerator::Skewb::LeftElementFactory
|
9
|
+
end
|
10
|
+
|
11
|
+
def border_points
|
12
|
+
[
|
13
|
+
[ x, y ],
|
14
|
+
[ x + side_size*2*units, y + side_size*units ],
|
15
|
+
[ x + side_size*2*units, y + side_size*3*units ],
|
16
|
+
[ x, y + side_size*2*units ]
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def rows
|
21
|
+
Array.new(side_size) do |i|
|
22
|
+
{
|
23
|
+
x1: x + (2*i)*units,
|
24
|
+
y1: y + (3*i+2)*units,
|
25
|
+
x2: x + (2*i+2)*units,
|
26
|
+
y2: y + (3*i+1)*units
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def columns
|
32
|
+
Array.new(side_size) do |i|
|
33
|
+
{
|
34
|
+
x1: x + (2*i)*units,
|
35
|
+
y1: y + (-1*i+2)*units,
|
36
|
+
x2: x + (i+1)*2*units,
|
37
|
+
y2: y + (-1*i+5)*units
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module GridGenerator
|
2
|
+
module Skewb
|
3
|
+
class RightElementFactory
|
4
|
+
def initialize(grid_x:, grid_y:, row_num:, col_num:, side_size:, units:, colour:, opacity:)
|
5
|
+
@grid_x, @grid_y = grid_x, grid_y
|
6
|
+
@row_num, @col_num = row_num, col_num
|
7
|
+
@side_size, @units = side_size, units
|
8
|
+
@colour, @opacity = colour, opacity
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :grid_x, :grid_y, :row_num, :col_num, :side_size, :units, :colour, :opacity
|
12
|
+
|
13
|
+
def x
|
14
|
+
@x ||= case [row_num, col_num]
|
15
|
+
when [0, 0] # Right Front
|
16
|
+
grid_x
|
17
|
+
when [0, side_size] # Right Up
|
18
|
+
grid_x+(side_size-1)*2*units
|
19
|
+
when [side_size, 0] # Right Down
|
20
|
+
grid_x
|
21
|
+
when [side_size, side_size] # Right Right
|
22
|
+
grid_x+(side_size-1)*2*units
|
23
|
+
when [(side_size/2),(side_size/2)] # Right Center
|
24
|
+
grid_x
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def y
|
31
|
+
@y ||= case [row_num, col_num]
|
32
|
+
when [0, 0] # Right Front
|
33
|
+
grid_y+(side_size-1)*units
|
34
|
+
when [0, side_size] # Right Up
|
35
|
+
grid_y
|
36
|
+
when [side_size, 0] # Right Down
|
37
|
+
grid_y+(2*side_size)*units
|
38
|
+
when [side_size, side_size] # Right Right
|
39
|
+
grid_y+(side_size-1)*2*units
|
40
|
+
when [(side_size/2),(side_size/2)] # Right Center
|
41
|
+
grid_y+(side_size/2)*units
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def points
|
48
|
+
case [row_num, col_num]
|
49
|
+
when [0, 0] # Right Front
|
50
|
+
[
|
51
|
+
[ x, y+units ],
|
52
|
+
[ x+2*units, y ],
|
53
|
+
[ x, y+3*units ]
|
54
|
+
]
|
55
|
+
when [0, side_size] # Right Up
|
56
|
+
[
|
57
|
+
[ x, y+units ],
|
58
|
+
[ x+2*units, y ],
|
59
|
+
[ x+2*units, y+2*units ]
|
60
|
+
]
|
61
|
+
when [side_size, 0] # Right Down
|
62
|
+
[
|
63
|
+
[ x, y ],
|
64
|
+
[ x+2*units, y+units ],
|
65
|
+
[ x, y+2*units ]
|
66
|
+
]
|
67
|
+
when [side_size, side_size] # Right Right
|
68
|
+
[
|
69
|
+
[ x+2*units, y ],
|
70
|
+
[ x+2*units, y+2*units ],
|
71
|
+
[ x, y+3*units ]
|
72
|
+
]
|
73
|
+
when [(side_size/2), (side_size/2)] # Right Center
|
74
|
+
[
|
75
|
+
[ x+2*units, y ],
|
76
|
+
[ x+4*units, y+units ],
|
77
|
+
[ x+2*units, y+4*units ],
|
78
|
+
[ x, y+3*units ]
|
79
|
+
]
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def build
|
86
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) unless points.empty?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require './lib/grid_generator/skewb/skewb_grid.rb'
|
2
|
+
require './lib/grid_generator/skewb/right_element_factory.rb'
|
3
|
+
|
4
|
+
module GridGenerator
|
5
|
+
module Skewb
|
6
|
+
class RightSkewbGrid < Skewb::SkewbGrid
|
7
|
+
def factory_class
|
8
|
+
GridGenerator::Skewb::RightElementFactory
|
9
|
+
end
|
10
|
+
|
11
|
+
def border_points
|
12
|
+
[
|
13
|
+
[ x, y + side_size*units ],
|
14
|
+
[ x + side_size*2*units, y ],
|
15
|
+
[ x + side_size*2*units, y + side_size*2*units ],
|
16
|
+
[ x, y + side_size*3*units ]
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def rows
|
21
|
+
Array.new(side_size) do |i|
|
22
|
+
{
|
23
|
+
x1: x + (2*i)*units,
|
24
|
+
y1: y + (i+4)*units,
|
25
|
+
x2: x + (2*i+2)*units,
|
26
|
+
y2: y + (i+1)*units
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def columns
|
32
|
+
Array.new(side_size) do |i|
|
33
|
+
{
|
34
|
+
x1: x + (2*i)*units,
|
35
|
+
y1: y + (-3*i+4)*units,
|
36
|
+
x2: x + (i+1)*2*units,
|
37
|
+
y2: y + (-3*i+5)*units
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|