geo_pattern 1.4.0 → 1.5.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.
Files changed (97) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +30 -0
  3. data/.gitignore +1 -0
  4. data/.simplecov +1 -0
  5. data/Gemfile +17 -19
  6. data/README.md +35 -12
  7. data/Rakefile +45 -49
  8. data/geo_pattern.gemspec +18 -22
  9. data/lib/geo_pattern/background.rb +9 -7
  10. data/lib/geo_pattern/background_generators/solid_generator.rb +4 -2
  11. data/lib/geo_pattern/color.rb +3 -1
  12. data/lib/geo_pattern/color_generators/base_color_generator.rb +12 -10
  13. data/lib/geo_pattern/color_generators/simple_generator.rb +2 -0
  14. data/lib/geo_pattern/color_preset.rb +7 -1
  15. data/lib/geo_pattern/errors.rb +2 -0
  16. data/lib/geo_pattern/geo_pattern_task.rb +11 -9
  17. data/lib/geo_pattern/helpers.rb +7 -5
  18. data/lib/geo_pattern/pattern.rb +6 -4
  19. data/lib/geo_pattern/pattern_generator.rb +14 -12
  20. data/lib/geo_pattern/pattern_helpers.rb +11 -8
  21. data/lib/geo_pattern/pattern_preset.rb +3 -1
  22. data/lib/geo_pattern/pattern_sieve.rb +5 -3
  23. data/lib/geo_pattern/pattern_store.rb +20 -18
  24. data/lib/geo_pattern/pattern_validator.rb +4 -2
  25. data/lib/geo_pattern/rake_task.rb +19 -16
  26. data/lib/geo_pattern/roles/comparable_metadata.rb +2 -0
  27. data/lib/geo_pattern/roles/named_generator.rb +3 -1
  28. data/lib/geo_pattern/seed.rb +2 -0
  29. data/lib/geo_pattern/structure.rb +9 -7
  30. data/lib/geo_pattern/structure_generators/base_generator.rb +17 -14
  31. data/lib/geo_pattern/structure_generators/chevrons_generator.rb +19 -17
  32. data/lib/geo_pattern/structure_generators/concentric_circles_generator.rb +19 -17
  33. data/lib/geo_pattern/structure_generators/diamonds_generator.rb +23 -17
  34. data/lib/geo_pattern/structure_generators/hexagons_generator.rb +25 -23
  35. data/lib/geo_pattern/structure_generators/mosaic_squares_generator.rb +35 -35
  36. data/lib/geo_pattern/structure_generators/nested_squares_generator.rb +23 -21
  37. data/lib/geo_pattern/structure_generators/octagons_generator.rb +12 -11
  38. data/lib/geo_pattern/structure_generators/overlapping_circles_generator.rb +13 -11
  39. data/lib/geo_pattern/structure_generators/overlapping_rings_generator.rb +15 -13
  40. data/lib/geo_pattern/structure_generators/plaid_generator.rb +18 -18
  41. data/lib/geo_pattern/structure_generators/plus_signs_generator.rb +24 -18
  42. data/lib/geo_pattern/structure_generators/sine_waves_generator.rb +17 -15
  43. data/lib/geo_pattern/structure_generators/squares_generator.rb +10 -9
  44. data/lib/geo_pattern/structure_generators/tessellation_generator.rb +36 -34
  45. data/lib/geo_pattern/structure_generators/triangles_generator.rb +22 -19
  46. data/lib/geo_pattern/structure_generators/xes_generator.rb +26 -19
  47. data/lib/geo_pattern/svg_image.rb +10 -8
  48. data/lib/geo_pattern/version.rb +3 -1
  49. data/lib/geo_pattern.rb +53 -51
  50. data/script/console +4 -3
  51. data/spec/background_generators/solid_generator_spec.rb +16 -14
  52. data/spec/background_spec.rb +13 -11
  53. data/spec/color_generators/base_color_generator_spec.rb +10 -8
  54. data/spec/color_generators/simple_generator_spec.rb +5 -3
  55. data/spec/color_preset_spec.rb +17 -15
  56. data/spec/color_spec.rb +8 -6
  57. data/spec/geo_pattern_spec.rb +59 -58
  58. data/spec/helpers_spec.rb +30 -28
  59. data/spec/pattern_preset_spec.rb +15 -13
  60. data/spec/pattern_sieve_spec.rb +13 -11
  61. data/spec/pattern_spec.rb +20 -18
  62. data/spec/pattern_store_spec.rb +21 -19
  63. data/spec/pattern_validator_spec.rb +11 -9
  64. data/spec/seed_spec.rb +6 -4
  65. data/spec/spec_helper.rb +9 -8
  66. data/spec/structure_generators/chevrons_generator_spec.rb +4 -2
  67. data/spec/structure_generators/concentric_circles_generator_spec.rb +4 -2
  68. data/spec/structure_generators/diamonds_generator_spec.rb +4 -2
  69. data/spec/structure_generators/hexagons_generator_spec.rb +4 -2
  70. data/spec/structure_generators/mosaic_squares_generator_spec.rb +4 -2
  71. data/spec/structure_generators/nested_squares_generator_spec.rb +4 -2
  72. data/spec/structure_generators/octagons_generator_spec.rb +4 -2
  73. data/spec/structure_generators/overlapping_circles_generator_spec.rb +4 -2
  74. data/spec/structure_generators/overlapping_rings_generator_spec.rb +4 -2
  75. data/spec/structure_generators/plaid_generator_spec.rb +4 -2
  76. data/spec/structure_generators/plus_signs_generator_spec.rb +4 -2
  77. data/spec/structure_generators/sine_waves_generator_spec.rb +4 -2
  78. data/spec/structure_generators/squares_generator_spec.rb +4 -2
  79. data/spec/structure_generators/tessellation_generator_spec.rb +4 -2
  80. data/spec/structure_generators/triangles_generator_spec.rb +4 -2
  81. data/spec/structure_generators/xes_generator_spec.rb +4 -2
  82. data/spec/structure_spec.rb +18 -16
  83. data/spec/support/aruba.rb +6 -6
  84. data/spec/support/helpers/fixtures.rb +3 -1
  85. data/spec/support/kernel.rb +8 -2
  86. data/spec/support/matchers/image.rb +4 -2
  87. data/spec/support/matchers/name.rb +3 -1
  88. data/spec/support/rspec.rb +4 -2
  89. data/spec/support/shared_examples/generator.rb +12 -10
  90. data/spec/support/shared_examples/pattern.rb +7 -5
  91. data/spec/support/shared_examples/pattern_name.rb +4 -2
  92. data/spec/support/shared_examples/structure.rb +12 -10
  93. data/spec/support/string.rb +3 -2
  94. data/spec/svg_spec.rb +5 -3
  95. metadata +11 -59
  96. data/.rubocop.yml +0 -71
  97. data/.travis.yml +0 -12
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class HexagonsGenerator < BaseGenerator
@@ -6,48 +8,48 @@ module GeoPattern
6
8
  attr_reader :scale, :side_length, :hex_height, :hex_width, :hex
7
9
 
8
10
  def after_initialize
9
- @scale = hex_val(0, 1)
11
+ @scale = hex_val(0, 1)
10
12
  @side_length = map(scale, 0, 15, 8, 60)
11
- @hex_height = side_length * Math.sqrt(3)
12
- @hex_width = side_length * 2
13
- @hex = build_hexagon_shape(side_length)
13
+ @hex_height = side_length * Math.sqrt(3)
14
+ @hex_width = side_length * 2
15
+ @hex = build_hexagon_shape(side_length)
14
16
 
15
- self.width = hex_width * 3 + side_length * 3
17
+ self.width = hex_width * 3 + side_length * 3
16
18
  self.height = hex_height * 6
17
19
  end
18
20
 
19
21
  def generate_structure
20
22
  i = 0
21
- for y in 0..5
22
- for x in 0..5
23
- val = hex_val(i, 1)
24
- dy = x % 2 == 0 ? y * hex_height : y * hex_height + hex_height / 2
23
+ 6.times do |y|
24
+ 6.times do |x|
25
+ val = hex_val(i, 1)
26
+ dy = (x % 2 == 0) ? y * hex_height : y * hex_height + hex_height / 2
25
27
  opacity = opacity(val)
26
- fill = fill_color(val)
28
+ fill = fill_color(val)
27
29
 
28
30
  styles = {
29
- 'fill' => fill,
30
- 'fill-opacity' => opacity,
31
- 'stroke' => stroke_color,
32
- 'stroke-opacity' => stroke_opacity
31
+ "fill" => fill,
32
+ "fill-opacity" => opacity,
33
+ "stroke" => stroke_color,
34
+ "stroke-opacity" => stroke_opacity
33
35
  }
34
36
 
35
- svg.polyline(hex, styles.merge('transform' => "translate(#{x * side_length * 1.5 - hex_width / 2}, #{dy - hex_height / 2})"))
37
+ svg.polyline(hex, styles.merge("transform" => "translate(#{x * side_length * 1.5 - hex_width / 2}, #{dy - hex_height / 2})"))
36
38
 
37
39
  # Add an extra one at top-right, for tiling.
38
- if (x == 0)
39
- svg.polyline(hex, styles.merge('transform' => "translate(#{6 * side_length * 1.5 - hex_width / 2}, #{dy - hex_height / 2})"))
40
+ if x == 0
41
+ svg.polyline(hex, styles.merge("transform" => "translate(#{6 * side_length * 1.5 - hex_width / 2}, #{dy - hex_height / 2})"))
40
42
  end
41
43
 
42
44
  # Add an extra row at the end that matches the first row, for tiling.
43
- if (y == 0)
44
- dy = x % 2 == 0 ? 6 * hex_height : 6 * hex_height + hex_height / 2
45
- svg.polyline(hex, styles.merge('transform' => "translate(#{x * side_length * 1.5 - hex_width / 2}, #{dy - hex_height / 2})"))
45
+ if y == 0
46
+ dy = (x % 2 == 0) ? 6 * hex_height : 6 * hex_height + hex_height / 2
47
+ svg.polyline(hex, styles.merge("transform" => "translate(#{x * side_length * 1.5 - hex_width / 2}, #{dy - hex_height / 2})"))
46
48
  end
47
49
 
48
50
  # Add an extra one at bottom-right, for tiling.
49
51
  if x == 0 && y == 0
50
- svg.polyline(hex, styles.merge('transform' => "translate(#{6 * side_length * 1.5 - hex_width / 2}, #{5 * hex_height + hex_height / 2})"))
52
+ svg.polyline(hex, styles.merge("transform" => "translate(#{6 * side_length * 1.5 - hex_width / 2}, #{5 * hex_height + hex_height / 2})"))
51
53
  end
52
54
  i += 1
53
55
  end
@@ -56,8 +58,8 @@ module GeoPattern
56
58
  svg
57
59
  end
58
60
 
59
- def build_hexagon_shape(sideLength)
60
- c = sideLength
61
+ def build_hexagon_shape(side_length)
62
+ c = side_length
61
63
  a = c / 2
62
64
  b = Math.sin(60 * Math::PI / 180) * c
63
65
  "0,#{b},#{a},0,#{a + c},0,#{2 * c},#{b},#{a + c},#{2 * b},#{a},#{2 * b},0,#{b}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class MosaicSquaresGenerator < BaseGenerator
@@ -13,20 +15,18 @@ module GeoPattern
13
15
 
14
16
  def generate_structure
15
17
  i = 0
16
- for y in 0..3
17
- for x in 0..3
18
+ 4.times do |y|
19
+ 4.times do |x|
18
20
  if x.even?
19
21
  if y.even?
20
22
  draw_outer_mosaic_tile(x * triangle_size * 2, y * triangle_size * 2, triangle_size, hex_val(i, 1))
21
23
  else
22
24
  draw_inner_mosaic_tile(x * triangle_size * 2, y * triangle_size * 2, triangle_size, [hex_val(i, 1), hex_val(i + 1, 1)])
23
25
  end
26
+ elsif y.even?
27
+ draw_inner_mosaic_tile(x * triangle_size * 2, y * triangle_size * 2, triangle_size, [hex_val(i, 1), hex_val(i + 1, 1)])
24
28
  else
25
- if y.even?
26
- draw_inner_mosaic_tile(x * triangle_size * 2, y * triangle_size * 2, triangle_size, [hex_val(i, 1), hex_val(i + 1, 1)])
27
- else
28
- draw_outer_mosaic_tile(x * triangle_size * 2, y * triangle_size * 2, triangle_size, hex_val(i, 1))
29
- end
29
+ draw_outer_mosaic_tile(x * triangle_size * 2, y * triangle_size * 2, triangle_size, hex_val(i, 1))
30
30
  end
31
31
  i += 1
32
32
  end
@@ -37,44 +37,44 @@ module GeoPattern
37
37
 
38
38
  def draw_inner_mosaic_tile(x, y, triangle_size, vals)
39
39
  triangle = build_right_triangle_shape(triangle_size)
40
- opacity = opacity(vals[0])
41
- fill = fill_color(vals[0])
42
- styles = {
43
- 'stroke' => stroke_color,
44
- 'stroke-opacity' => stroke_opacity,
45
- 'fill-opacity' => opacity,
46
- 'fill' => fill
40
+ opacity = opacity(vals[0])
41
+ fill = fill_color(vals[0])
42
+ styles = {
43
+ "stroke" => stroke_color,
44
+ "stroke-opacity" => stroke_opacity,
45
+ "fill-opacity" => opacity,
46
+ "fill" => fill
47
47
  }
48
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x + triangle_size}, #{y}) scale(-1, 1)"))
49
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x + triangle_size}, #{y + triangle_size * 2}) scale(1, -1)"))
48
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x + triangle_size}, #{y}) scale(-1, 1)"))
49
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x + triangle_size}, #{y + triangle_size * 2}) scale(1, -1)"))
50
50
 
51
51
  opacity = opacity(vals[1])
52
- fill = fill_color(vals[1])
53
- styles = {
54
- 'stroke' => stroke_color,
55
- 'stroke-opacity' => stroke_opacity,
56
- 'fill-opacity' => opacity,
57
- 'fill' => fill
52
+ fill = fill_color(vals[1])
53
+ styles = {
54
+ "stroke" => stroke_color,
55
+ "stroke-opacity" => stroke_opacity,
56
+ "fill-opacity" => opacity,
57
+ "fill" => fill
58
58
  }
59
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x + triangle_size}, #{y + triangle_size * 2}) scale(-1, -1)"))
60
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x + triangle_size}, #{y}) scale(1, 1)"))
59
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x + triangle_size}, #{y + triangle_size * 2}) scale(-1, -1)"))
60
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x + triangle_size}, #{y}) scale(1, 1)"))
61
61
  end
62
62
 
63
63
  def draw_outer_mosaic_tile(x, y, triangle_size, val)
64
- opacity = opacity(val)
65
- fill = fill_color(val)
64
+ opacity = opacity(val)
65
+ fill = fill_color(val)
66
66
  triangle = build_right_triangle_shape(triangle_size)
67
- styles = {
68
- 'stroke' => stroke_color,
69
- 'stroke-opacity' => stroke_opacity,
70
- 'fill-opacity' => opacity,
71
- 'fill' => fill
67
+ styles = {
68
+ "stroke" => stroke_color,
69
+ "stroke-opacity" => stroke_opacity,
70
+ "fill-opacity" => opacity,
71
+ "fill" => fill
72
72
  }
73
73
 
74
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x}, #{y + triangle_size}) scale(1, -1)"))
75
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x + triangle_size * 2}, #{y + triangle_size}) scale(-1, -1)"))
76
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x}, #{y + triangle_size}) scale(1, 1)"))
77
- svg.polyline(triangle, styles.merge('transform' => "translate(#{x + triangle_size * 2}, #{y + triangle_size}) scale(-1, 1)"))
74
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x}, #{y + triangle_size}) scale(1, -1)"))
75
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x + triangle_size * 2}, #{y + triangle_size}) scale(-1, -1)"))
76
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x}, #{y + triangle_size}) scale(1, 1)"))
77
+ svg.polyline(triangle, styles.merge("transform" => "translate(#{x + triangle_size * 2}, #{y + triangle_size}) scale(-1, 1)"))
78
78
  end
79
79
 
80
80
  def build_right_triangle_shape(side_length)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class NestedSquaresGenerator < BaseGenerator
@@ -9,46 +11,46 @@ module GeoPattern
9
11
  @block_size = map(hex_val(0, 1), 0, 15, 4, 12)
10
12
  @square_size = block_size * 7
11
13
 
12
- self.height = self.width = (square_size + block_size) * 6 + block_size * 6
14
+ self.height = self.width = (square_size + block_size) * 6 + block_size * 6
13
15
  end
14
16
 
15
17
  def generate_structure
16
18
  i = 0
17
- for y in 0..5
18
- for x in 0..5
19
- val = hex_val(i, 1)
19
+ 6.times do |y|
20
+ 6.times do |x|
21
+ val = hex_val(i, 1)
20
22
  opacity = opacity(val)
21
- fill = fill_color(val)
23
+ fill = fill_color(val)
22
24
 
23
25
  styles = {
24
- 'fill' => 'none',
25
- 'stroke' => fill,
26
- 'style' => {
27
- 'opacity' => opacity,
28
- 'stroke-width' => "#{block_size}px"
26
+ "fill" => "none",
27
+ "stroke" => fill,
28
+ "style" => {
29
+ "opacity" => opacity,
30
+ "stroke-width" => "#{block_size}px"
29
31
  }
30
32
  }
31
33
 
32
34
  svg.rect(x * square_size + x * block_size * 2 + block_size / 2,
33
- y * square_size + y * block_size * 2 + block_size / 2,
34
- square_size, square_size, styles)
35
+ y * square_size + y * block_size * 2 + block_size / 2,
36
+ square_size, square_size, styles)
35
37
 
36
- val = hex_val(39 - i, 1)
38
+ val = hex_val(39 - i, 1)
37
39
  opacity = opacity(val)
38
- fill = fill_color(val)
40
+ fill = fill_color(val)
39
41
 
40
42
  styles = {
41
- 'fill' => 'none',
42
- 'stroke' => fill,
43
- 'style' => {
44
- 'opacity' => opacity,
45
- 'stroke-width' => "#{block_size}px"
43
+ "fill" => "none",
44
+ "stroke" => fill,
45
+ "style" => {
46
+ "opacity" => opacity,
47
+ "stroke-width" => "#{block_size}px"
46
48
  }
47
49
  }
48
50
 
49
51
  svg.rect(x * square_size + x * block_size * 2 + block_size / 2 + block_size * 2,
50
- y * square_size + y * block_size * 2 + block_size / 2 + block_size * 2,
51
- block_size * 3, block_size * 3, styles)
52
+ y * square_size + y * block_size * 2 + block_size / 2 + block_size * 2,
53
+ block_size * 3, block_size * 3, styles)
52
54
  i += 1
53
55
  end
54
56
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class OctagonsGenerator < BaseGenerator
@@ -7,26 +9,25 @@ module GeoPattern
7
9
 
8
10
  def after_initialize
9
11
  @square_size = map(hex_val(0, 1), 0, 15, 10, 60)
10
- @tile = build_octogon_shape(square_size)
12
+ @tile = build_octogon_shape(square_size)
11
13
 
12
14
  self.height = self.width = square_size * 6
13
15
  end
14
16
 
15
17
  def generate_structure
16
18
  i = 0
17
- for y in 0..5
18
- for x in 0..5
19
- val = hex_val(i, 1)
19
+ 6.times do |y|
20
+ 6.times do |x|
21
+ val = hex_val(i, 1)
20
22
  opacity = opacity(val)
21
- fill = fill_color(val)
23
+ fill = fill_color(val)
22
24
 
23
25
  svg.polyline(tile,
24
- 'fill' => fill,
25
- 'fill-opacity' => opacity,
26
- 'stroke' => stroke_color,
27
- 'stroke-opacity' => stroke_opacity,
28
- 'transform' => "translate(#{x * square_size}, #{y * square_size})"
29
- )
26
+ "fill" => fill,
27
+ "fill-opacity" => opacity,
28
+ "stroke" => stroke_color,
29
+ "stroke-opacity" => stroke_opacity,
30
+ "transform" => "translate(#{x * square_size}, #{y * square_size})")
30
31
  i += 1
31
32
  end
32
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class OverlappingCirclesGenerator < BaseGenerator
@@ -6,37 +8,37 @@ module GeoPattern
6
8
  attr_reader :scale, :diameter, :radius
7
9
 
8
10
  def after_initialize
9
- @scale = hex_val(0, 1)
11
+ @scale = hex_val(0, 1)
10
12
  @diameter = map(scale, 0, 15, 25, 200)
11
- @radius = diameter / 2
13
+ @radius = diameter / 2
12
14
 
13
15
  self.height = self.width = radius * 6
14
16
  end
15
17
 
16
18
  def generate_structure
17
19
  i = 0
18
- for y in 0..5
19
- for x in 0..5
20
- val = hex_val(i, 1)
20
+ 6.times do |y|
21
+ 6.times do |x|
22
+ val = hex_val(i, 1)
21
23
  opacity = opacity(val)
22
- fill = fill_color(val)
24
+ fill = fill_color(val)
23
25
 
24
26
  styles = {
25
- 'fill' => fill,
26
- 'style' => {
27
- 'opacity' => opacity
27
+ "fill" => fill,
28
+ "style" => {
29
+ "opacity" => opacity
28
30
  }
29
31
  }
30
32
 
31
33
  svg.circle(x * radius, y * radius, radius, styles)
32
34
 
33
35
  # Add an extra one at top-right, for tiling.
34
- if (x == 0)
36
+ if x == 0
35
37
  svg.circle(6 * radius, y * radius, radius, styles)
36
38
  end
37
39
 
38
40
  # Add an extra row at the end that matches the first row, for tiling.
39
- if (y == 0)
41
+ if y == 0
40
42
  svg.circle(x * radius, 6 * radius, radius, styles)
41
43
  end
42
44
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class OverlappingRingsGenerator < BaseGenerator
@@ -6,8 +8,8 @@ module GeoPattern
6
8
  attr_reader :scale, :ring_size, :stroke_width
7
9
 
8
10
  def after_initialize
9
- @scale = hex_val(0, 1)
10
- @ring_size = map(scale, 0, 15, 10, 60)
11
+ @scale = hex_val(0, 1)
12
+ @ring_size = map(scale, 0, 15, 10, 60)
11
13
  @stroke_width = ring_size / 4
12
14
 
13
15
  self.height = self.width = ring_size * 6
@@ -15,29 +17,29 @@ module GeoPattern
15
17
 
16
18
  def generate_structure
17
19
  i = 0
18
- for y in 0..5
19
- for x in 0..5
20
- val = hex_val(i, 1)
20
+ 6.times do |y|
21
+ 6.times do |x|
22
+ val = hex_val(i, 1)
21
23
  opacity = opacity(val)
22
- fill = fill_color(val)
24
+ fill = fill_color(val)
23
25
 
24
26
  styles = {
25
- 'fill' => 'none',
26
- 'stroke' => fill,
27
- 'style' => {
28
- 'opacity' => opacity,
29
- 'stroke-width' => "#{stroke_width}px"
27
+ "fill" => "none",
28
+ "stroke" => fill,
29
+ "style" => {
30
+ "opacity" => opacity,
31
+ "stroke-width" => "#{stroke_width}px"
30
32
  }
31
33
  }
32
34
 
33
35
  svg.circle(x * ring_size, y * ring_size, ring_size - stroke_width / 2, styles)
34
36
 
35
37
  # Add an extra one at top-right, for tiling.
36
- if (x == 0)
38
+ if x == 0
37
39
  svg.circle(6 * ring_size, y * ring_size, ring_size - stroke_width / 2, styles)
38
40
  end
39
41
 
40
- if (y == 0)
42
+ if y == 0
41
43
  svg.circle(x * ring_size, 6 * ring_size, ring_size - stroke_width / 2, styles)
42
44
  end
43
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class PlaidGenerator < BaseGenerator
@@ -5,23 +7,22 @@ module GeoPattern
5
7
 
6
8
  def generate_structure
7
9
  local_height = 0
8
- local_width = 0
10
+ local_width = 0
9
11
 
10
12
  # horizontal stripes
11
13
  i = 0
12
14
  18.times do
13
- space = hex_val(i, 1)
15
+ space = hex_val(i, 1)
14
16
  local_height += space + 5
15
17
 
16
- val = hex_val(i + 1, 1)
17
- opacity = opacity(val)
18
- fill = fill_color(val)
18
+ val = hex_val(i + 1, 1)
19
+ opacity = opacity(val)
20
+ fill = fill_color(val)
19
21
  stripe_height = val + 5
20
22
 
21
- svg.rect(0, local_height, '100%', stripe_height,
22
- 'opacity' => opacity,
23
- 'fill' => fill
24
- )
23
+ svg.rect(0, local_height, "100%", stripe_height,
24
+ "opacity" => opacity,
25
+ "fill" => fill)
25
26
  local_height += stripe_height
26
27
  i += 2
27
28
  end
@@ -29,24 +30,23 @@ module GeoPattern
29
30
  # vertical stripes
30
31
  i = 0
31
32
  18.times do
32
- space = hex_val(i, 1)
33
+ space = hex_val(i, 1)
33
34
  local_width += space + 5
34
35
 
35
- val = hex_val(i + 1, 1)
36
- opacity = opacity(val)
37
- fill = fill_color(val)
36
+ val = hex_val(i + 1, 1)
37
+ opacity = opacity(val)
38
+ fill = fill_color(val)
38
39
  stripe_width = val + 5
39
40
 
40
- svg.rect(local_width, 0, stripe_width, '100%',
41
- 'opacity' => opacity,
42
- 'fill' => fill
43
- )
41
+ svg.rect(local_width, 0, stripe_width, "100%",
42
+ "opacity" => opacity,
43
+ "fill" => fill)
44
44
  local_width += stripe_width
45
45
  i += 2
46
46
  end
47
47
 
48
48
  self.height = local_height
49
- self.width = local_width
49
+ self.width = local_width
50
50
 
51
51
  svg
52
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class PlusSignsGenerator < BaseGenerator
@@ -7,49 +9,53 @@ module GeoPattern
7
9
 
8
10
  def after_initialize
9
11
  @square_size = map(hex_val(0, 1), 0, 15, 10, 25)
10
- @plus_size = square_size * 3
11
- @plus_shape = build_plus_shape(square_size)
12
+ @plus_size = square_size * 3
13
+ @plus_shape = build_plus_shape(square_size)
12
14
 
13
15
  self.height = self.width = square_size * 12
14
16
  end
15
17
 
16
18
  def generate_structure
17
19
  i = 0
18
- for y in 0..5
19
- for x in 0..5
20
- val = hex_val(i, 1)
20
+ 6.times do |y|
21
+ 6.times do |x|
22
+ val = hex_val(i, 1)
21
23
  opacity = opacity(val)
22
- fill = fill_color(val)
23
- dx = (y % 2 == 0) ? 0 : 1
24
+ fill = fill_color(val)
25
+ dx = (y % 2 == 0) ? 0 : 1
24
26
 
25
27
  styles = {
26
- 'fill' => fill,
27
- 'stroke' => stroke_color,
28
- 'stroke-opacity' => stroke_opacity,
29
- 'style' => {
30
- 'fill-opacity' => opacity
28
+ "fill" => fill,
29
+ "stroke" => stroke_color,
30
+ "stroke-opacity" => stroke_opacity,
31
+ "style" => {
32
+ "fill-opacity" => opacity
31
33
  }
32
34
  }
33
35
 
34
36
  svg.group(plus_shape, styles.merge(
35
- 'transform' => "translate(#{x * plus_size - x * square_size + dx * square_size - square_size},#{y * plus_size - y * square_size - plus_size / 2})"))
37
+ "transform" => "translate(#{x * plus_size - x * square_size + dx * square_size - square_size},#{y * plus_size - y * square_size - plus_size / 2})"
38
+ ))
36
39
 
37
40
  # Add an extra column on the right for tiling.
38
- if (x == 0)
41
+ if x == 0
39
42
  svg.group(plus_shape, styles.merge(
40
- 'transform' => "translate(#{4 * plus_size - x * square_size + dx * square_size - square_size},#{y * plus_size - y * square_size - plus_size / 2})"))
43
+ "transform" => "translate(#{4 * plus_size - x * square_size + dx * square_size - square_size},#{y * plus_size - y * square_size - plus_size / 2})"
44
+ ))
41
45
  end
42
46
 
43
47
  # Add an extra row on the bottom that matches the first row, for tiling.
44
- if (y == 0)
48
+ if y == 0
45
49
  svg.group(plus_shape, styles.merge(
46
- 'transform' => "translate(#{x * plus_size - x * square_size + dx * square_size - square_size},#{4 * plus_size - y * square_size - plus_size / 2})"))
50
+ "transform" => "translate(#{x * plus_size - x * square_size + dx * square_size - square_size},#{4 * plus_size - y * square_size - plus_size / 2})"
51
+ ))
47
52
  end
48
53
 
49
54
  # Add an extra one at top-right and bottom-right, for tiling.
50
55
  if x == 0 && y == 0
51
56
  svg.group(plus_shape, styles.merge(
52
- 'transform' => "translate(#{4 * plus_size - x * square_size + dx * square_size - square_size},#{4 * plus_size - y * square_size - plus_size / 2})"))
57
+ "transform" => "translate(#{4 * plus_size - x * square_size + dx * square_size - square_size},#{4 * plus_size - y * square_size - plus_size / 2})"
58
+ ))
53
59
  end
54
60
  i += 1
55
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoPattern
2
4
  module StructureGenerators
3
5
  class SineWavesGenerator < BaseGenerator
@@ -6,34 +8,34 @@ module GeoPattern
6
8
  attr_reader :period, :amplitude, :wave_width
7
9
 
8
10
  def after_initialize
9
- @period = map(hex_val(0, 1), 0, 15, 100, 400).floor
10
- @amplitude = map(hex_val(1, 1), 0, 15, 30, 100).floor
11
+ @period = map(hex_val(0, 1), 0, 15, 100, 400).floor
12
+ @amplitude = map(hex_val(1, 1), 0, 15, 30, 100).floor
11
13
  @wave_width = map(hex_val(2, 1), 0, 15, 3, 30).floor
12
14
 
13
15
  self.height = wave_width * 36
14
- self.width = period
16
+ self.width = period
15
17
  end
16
18
 
17
19
  def generate_structure
18
- for i in 0..35
19
- val = hex_val(i, 1)
20
- opacity = opacity(val)
21
- fill = fill_color(val)
20
+ 36.times do |i|
21
+ val = hex_val(i, 1)
22
+ opacity = opacity(val)
23
+ fill = fill_color(val)
22
24
  x_offset = period / 4 * 0.7
23
25
 
24
26
  styles = {
25
- 'fill' => 'none',
26
- 'stroke' => fill,
27
- 'style' => {
28
- 'opacity' => opacity,
29
- 'stroke-width' => "#{wave_width}px"
27
+ "fill" => "none",
28
+ "stroke" => fill,
29
+ "style" => {
30
+ "opacity" => opacity,
31
+ "stroke-width" => "#{wave_width}px"
30
32
  }
31
33
  }
32
34
 
33
- str = 'M0 ' + amplitude.to_s + ' C ' + x_offset.to_s + ' 0, ' + (period / 2 - x_offset).to_s + ' 0, ' + (period / 2).to_s + ' ' + amplitude.to_s + ' S ' + (period - x_offset).to_s + ' ' + (amplitude * 2).to_s + ', ' + period.to_s + ' ' + amplitude.to_s + ' S ' + (period * 1.5 - x_offset).to_s + ' 0, ' + (period * 1.5).to_s + ', ' + amplitude.to_s
35
+ str = "M0 #{amplitude} C #{x_offset} 0, #{period / 2 - x_offset} 0, #{period / 2} #{amplitude} S #{period - x_offset} #{amplitude * 2}, #{period} #{amplitude} S #{period * 1.5 - x_offset} 0, #{period * 1.5}, #{amplitude}"
34
36
 
35
- svg.path(str, styles.merge('transform' => "translate(-#{period / 4}, #{wave_width * i - amplitude * 1.5})"))
36
- svg.path(str, styles.merge('transform' => "translate(-#{period / 4}, #{wave_width * i - amplitude * 1.5 + wave_width * 36})"))
37
+ svg.path(str, styles.merge("transform" => "translate(-#{period / 4}, #{wave_width * i - amplitude * 1.5})"))
38
+ svg.path(str, styles.merge("transform" => "translate(-#{period / 4}, #{wave_width * i - amplitude * 1.5 + wave_width * 36})"))
37
39
  end
38
40
 
39
41
  svg