grid_generator 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d75cdb06a79ebb644afccc577353a18b2a7f999251ffffd6f1f7617b08c23745
4
- data.tar.gz: fb3fc73597223fed891b6857250e217f9c4ca057e1795574b2ae1a9fd2ce1c41
3
+ metadata.gz: f26be22e443d706a070b3610b275de01024997c550ed65d106afc6193e8fe0f3
4
+ data.tar.gz: 41ee0e26215d6d6296907a735c93b0a832b9418fd2d1cdf0121404b3db6e8b7c
5
5
  SHA512:
6
- metadata.gz: 06f2a4c827b2710abc6a379f6a45360a7caabafa4b0905f466e975968c0a622bb1f87296d7409b6225dabc7f807f126b4c93633af4b8a449830eb27703a5aee7
7
- data.tar.gz: 1cb5b6a79655216376731edcd9724ceb9dd9cb5e6236df9cab39c8e048754a0aca33a17413a71d87aeb8985c48a74ad0500ac8f1035b2c7784a948db9b3f3976
6
+ metadata.gz: 6eedfb3bdc00baa6eec0b8173afb35efdafb2e5583a354d128f9e078ddd26e768785bf0a8a3f095b830d8b9f4fc93c131c4191c7c33c779bceb826078a1bdda1
7
+ data.tar.gz: f9029ee7f2f8c80e72e72a83f7792f5b941075f3d0e074ee8704b8c84cf3342a5c354e006b07c6e7c0e0b486c3702f8c2d89c526a319c0e9a0ce4b4a116355b6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.3.0)
4
+ grid_generator (0.3.1)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -1,5 +1,10 @@
1
1
  module GridGenerator
2
2
  class BaseElement
3
+ COLOURS = {
4
+ fill: "#d0d0d0",
5
+ stroke: "#404040"
6
+ }
7
+
3
8
  def initialize(points:, colour: , opacity: 1)
4
9
  @points = points
5
10
  @colour = colour
@@ -26,5 +31,9 @@ module GridGenerator
26
31
  "opacity" => opacity
27
32
  }
28
33
  end
34
+
35
+ def to_svg
36
+ "<polygon points=\"#{points_string}}\" style=\"fill:#{colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{opacity}\" />"
37
+ end
29
38
  end
30
39
  end
@@ -6,6 +6,11 @@ require_relative 'facing_square_factory'
6
6
  module GridGenerator
7
7
  module Cubic
8
8
  class BorderedGrid
9
+ COLOURS = {
10
+ fill: "#d0d0d0",
11
+ stroke: "#404040"
12
+ }
13
+
9
14
  def initialize(x:, y:, units:, squares: )
10
15
  @x, @y = x, y
11
16
  @units = units
@@ -136,6 +141,24 @@ module GridGenerator
136
141
  "element_shapes" => element_shapes.map(&:as_json)
137
142
  }
138
143
  end
144
+
145
+ def to_svg
146
+ output = "<polygon points=\"#{points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
147
+
148
+ for row in rows do
149
+ output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
150
+ end
151
+
152
+ for col in columns do
153
+ output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
154
+ end
155
+
156
+ for shape in element_shapes do
157
+ output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
158
+ end
159
+
160
+ output
161
+ end
139
162
  end
140
163
  end
141
164
  end
@@ -6,6 +6,11 @@ require_relative 'facing_square_factory'
6
6
  module GridGenerator
7
7
  module Cubic
8
8
  class FacingGrid
9
+ COLOURS = {
10
+ fill: "#d0d0d0",
11
+ stroke: "#404040"
12
+ }
13
+
9
14
  def initialize(x:, y:, units:, squares: )
10
15
  @x, @y = x, y
11
16
  @units = units
@@ -116,6 +121,24 @@ module GridGenerator
116
121
  "element_shapes" => element_shapes.map(&:as_json)
117
122
  }
118
123
  end
124
+
125
+ def to_svg
126
+ output = "<polygon points=\"#{points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
127
+
128
+ for row in rows do
129
+ output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
130
+ end
131
+
132
+ for col in columns do
133
+ output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
134
+ end
135
+
136
+ for shape in element_shapes do
137
+ output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
138
+ end
139
+
140
+ output
141
+ end
119
142
  end
120
143
  end
121
144
  end
@@ -4,6 +4,11 @@ require_relative '../line'
4
4
  module GridGenerator
5
5
  module Cubic
6
6
  class Grid
7
+ COLOURS = {
8
+ fill: "#d0d0d0",
9
+ stroke: "#404040"
10
+ }
11
+
7
12
  def initialize(x:, y:, units: , squares: )
8
13
  @x, @y = x, y
9
14
  @units = units
@@ -161,6 +166,24 @@ module GridGenerator
161
166
  "element_shapes" => element_shapes.map(&:as_json)
162
167
  }
163
168
  end
169
+
170
+ def to_svg
171
+ output = "<polygon points=\"#{points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
172
+
173
+ for row in rows do
174
+ output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
175
+ end
176
+
177
+ for col in columns do
178
+ output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
179
+ end
180
+
181
+ for shape in element_shapes do
182
+ output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
183
+ end
184
+
185
+ output
186
+ end
164
187
  end
165
188
  end
166
189
  end
@@ -29,6 +29,13 @@ module GridGenerator
29
29
  "right" => right.as_json
30
30
  }
31
31
  end
32
+
33
+ def to_svg
34
+ output = top.to_svg
35
+ output += front.to_svg
36
+ output += right.to_svg
37
+ output
38
+ end
32
39
  end
33
40
  end
34
41
  end
@@ -7,6 +7,10 @@ require_relative 'face_element_factory'
7
7
  module GridGenerator
8
8
  module Megaminx
9
9
  class FaceProjection
10
+ COLOURS = {
11
+ fill: "#d0d0d0",
12
+ stroke: "#404040"
13
+ }
10
14
  # units 30 - pentagon 90 - megaminx - 150
11
15
  # units * 5
12
16
  def initialize(x:, y:, units:, front_face_elements: "", top_right_face_elements: "", right_face_elements: "", down_face_elements: "", left_face_elements: "", top_left_face_elements: "", rotation_offset: 0)
@@ -205,6 +209,37 @@ module GridGenerator
205
209
  end.compact
206
210
  end
207
211
  end
212
+
213
+ def to_svg
214
+ output = "<polygon points=\"#{ decagon_points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1\" />"
215
+ output += "<polygon points=\"#{ pentagon_points_string }\" style=\"fill:none;stroke:#{ COLOURS[:stroke] };stroke-width:1\" />"
216
+
217
+ for line in connecting_lines do
218
+ output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
219
+ end
220
+
221
+ for line in front_face_lines do
222
+ output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
223
+ end
224
+
225
+ for face in outside_face_lines do
226
+ for line in face do
227
+ output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
228
+ end
229
+ end
230
+
231
+ for shape in front_face_element_shapes do
232
+ output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
233
+ end
234
+
235
+ for face in outside_face_element_shapes do
236
+ for shape in face do
237
+ output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
238
+ end
239
+ end
240
+
241
+ output
242
+ end
208
243
  end
209
244
  end
210
245
  end
@@ -9,6 +9,11 @@ module GridGenerator
9
9
  # * * *
10
10
  # * * * * *
11
11
  class Face
12
+ COLOURS = {
13
+ fill: "#d0d0d0",
14
+ stroke: "#404040"
15
+ }
16
+
12
17
  def initialize(x:, y:, units:, elements:, vertical_scale: 1, rotation_angle: 0)
13
18
  @x, @y = x, y
14
19
  @units = units
@@ -190,6 +195,28 @@ module GridGenerator
190
195
  end
191
196
  end.flatten.compact
192
197
  end
198
+
199
+ def to_svg
200
+ output = "<polygon points=\"#{ points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1\" />"
201
+
202
+ for line in vertical_lines do
203
+ output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
204
+ end
205
+
206
+ for line in diagonal_up_lines do
207
+ output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
208
+ end
209
+
210
+ for line in diagonal_down_lines do
211
+ output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
212
+ end
213
+
214
+ element_shapes.map do |shape|
215
+ output += "<polygon points=\"#{ shape.points_string }\" style=\"fill:#{ shape.colour };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:#{ shape.opacity }\" />"
216
+ end
217
+
218
+ output
219
+ end
193
220
  end
194
221
  end
195
222
  end
@@ -5,6 +5,11 @@ require_relative 'left_element_factory'
5
5
  module GridGenerator
6
6
  module Skewb
7
7
  class LeftSkewbGrid < Skewb::SkewbGrid
8
+ COLOURS = {
9
+ fill: "#d0d0d0",
10
+ stroke: "#404040"
11
+ }
12
+
8
13
  def factory_class
9
14
  GridGenerator::Skewb::LeftElementFactory
10
15
  end
@@ -49,6 +54,26 @@ module GridGenerator
49
54
  GridGenerator::Line.new(a: a, b: b)
50
55
  end
51
56
  end
57
+
58
+ def to_svg
59
+ output = "<polygon points=\"#{border_points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
60
+
61
+ rows.each do |row|
62
+ output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
63
+ end
64
+
65
+ columns.each do |col|
66
+ output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
67
+ end
68
+
69
+ element_shapes.each do |element|
70
+ if element
71
+ output += "<polygon points=\"#{element.points_string}\" style=\"fill:#{element.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{element.opacity}\" />"
72
+ end
73
+ end
74
+
75
+ output
76
+ end
52
77
  end
53
78
  end
54
79
  end
@@ -6,6 +6,11 @@ require_relative 'right_element_factory.rb'
6
6
  module GridGenerator
7
7
  module Skewb
8
8
  class RightSkewbGrid < Skewb::SkewbGrid
9
+ COLOURS = {
10
+ fill: "#d0d0d0",
11
+ stroke: "#404040"
12
+ }
13
+
9
14
  def factory_class
10
15
  GridGenerator::Skewb::RightElementFactory
11
16
  end
@@ -50,6 +55,26 @@ module GridGenerator
50
55
  GridGenerator::Line.new(a: a, b: b)
51
56
  end
52
57
  end
58
+
59
+ def to_svg
60
+ output = "<polygon points=\"#{border_points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
61
+
62
+ rows.each do |row|
63
+ output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
64
+ end
65
+
66
+ columns.each do |col|
67
+ output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
68
+ end
69
+
70
+ element_shapes.each do |element|
71
+ if element
72
+ output += "<polygon points=\"#{element.points_string}\" style=\"fill:#{element.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{element.opacity}\" />"
73
+ end
74
+ end
75
+
76
+ output
77
+ end
53
78
  end
54
79
  end
55
80
  end
@@ -6,6 +6,11 @@ require_relative 'top_element_factory'
6
6
  module GridGenerator
7
7
  module Skewb
8
8
  class TopSkewbGrid < Skewb::SkewbGrid
9
+ COLOURS = {
10
+ fill: "#d0d0d0",
11
+ stroke: "#404040"
12
+ }
13
+
9
14
  def factory_class
10
15
  GridGenerator::Skewb::TopElementFactory
11
16
  end
@@ -50,6 +55,26 @@ module GridGenerator
50
55
  GridGenerator::Line.new(a: a, b: b)
51
56
  end
52
57
  end
58
+
59
+ def to_svg
60
+ output = "<polygon points=\"#{border_points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
61
+
62
+ rows.each do |row|
63
+ output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
64
+ end
65
+
66
+ columns.each do |col|
67
+ output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
68
+ end
69
+
70
+ element_shapes.each do |element|
71
+ if element
72
+ output += "<polygon points=\"#{element.points_string}\" style=\"fill:#{element.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{element.opacity}\" />"
73
+ end
74
+ end
75
+
76
+ output
77
+ end
53
78
  end
54
79
  end
55
80
  end
@@ -5,6 +5,11 @@ require_relative 'element_factory'
5
5
  module GridGenerator
6
6
  module SquareOne
7
7
  class Face
8
+ COLOURS = {
9
+ fill: "#d0d0d0",
10
+ stroke: "#404040"
11
+ }
12
+
8
13
  def initialize(x:, y: , units: , elements:, axis_direction: :forward)
9
14
  @x, @y = x, y
10
15
  @units = units
@@ -88,6 +93,20 @@ module GridGenerator
88
93
  "element_shapes" => element_shapes.map(&:as_json)
89
94
  }
90
95
  end
96
+
97
+ def to_svg
98
+ output = ""
99
+ element_shapes.each do |element|
100
+ if element.opacity == 0.4
101
+ output += "<polygon points=\"#{ element.points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:1;]\" />"
102
+ end
103
+ output += "<polygon points=\"#{ element.points_string }\" style=\"fill:#{ element.colour };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:#{ element.opacity };\" />"
104
+ end
105
+
106
+ output += "<line x1=\"#{ axis.x1 }\" y1=\"#{ axis.y1 }\" x2=\"#{ axis.x2 }\" y2=\"#{ axis.y2 }\" style=\"stroke:#{ COLOURS[:stroke] };stroke-width:5\" />"
107
+
108
+ output
109
+ end
91
110
  end
92
111
  end
93
112
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grid_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Humphreys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-22 00:00:00.000000000 Z
11
+ date: 2023-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix