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.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +30 -0
- data/.gitignore +1 -0
- data/.simplecov +1 -0
- data/Gemfile +17 -19
- data/README.md +35 -12
- data/Rakefile +45 -49
- data/geo_pattern.gemspec +18 -22
- data/lib/geo_pattern/background.rb +9 -7
- data/lib/geo_pattern/background_generators/solid_generator.rb +4 -2
- data/lib/geo_pattern/color.rb +3 -1
- data/lib/geo_pattern/color_generators/base_color_generator.rb +12 -10
- data/lib/geo_pattern/color_generators/simple_generator.rb +2 -0
- data/lib/geo_pattern/color_preset.rb +7 -1
- data/lib/geo_pattern/errors.rb +2 -0
- data/lib/geo_pattern/geo_pattern_task.rb +11 -9
- data/lib/geo_pattern/helpers.rb +7 -5
- data/lib/geo_pattern/pattern.rb +6 -4
- data/lib/geo_pattern/pattern_generator.rb +14 -12
- data/lib/geo_pattern/pattern_helpers.rb +11 -8
- data/lib/geo_pattern/pattern_preset.rb +3 -1
- data/lib/geo_pattern/pattern_sieve.rb +5 -3
- data/lib/geo_pattern/pattern_store.rb +20 -18
- data/lib/geo_pattern/pattern_validator.rb +4 -2
- data/lib/geo_pattern/rake_task.rb +19 -16
- data/lib/geo_pattern/roles/comparable_metadata.rb +2 -0
- data/lib/geo_pattern/roles/named_generator.rb +3 -1
- data/lib/geo_pattern/seed.rb +2 -0
- data/lib/geo_pattern/structure.rb +9 -7
- data/lib/geo_pattern/structure_generators/base_generator.rb +17 -14
- data/lib/geo_pattern/structure_generators/chevrons_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/concentric_circles_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/diamonds_generator.rb +23 -17
- data/lib/geo_pattern/structure_generators/hexagons_generator.rb +25 -23
- data/lib/geo_pattern/structure_generators/mosaic_squares_generator.rb +35 -35
- data/lib/geo_pattern/structure_generators/nested_squares_generator.rb +23 -21
- data/lib/geo_pattern/structure_generators/octagons_generator.rb +12 -11
- data/lib/geo_pattern/structure_generators/overlapping_circles_generator.rb +13 -11
- data/lib/geo_pattern/structure_generators/overlapping_rings_generator.rb +15 -13
- data/lib/geo_pattern/structure_generators/plaid_generator.rb +18 -18
- data/lib/geo_pattern/structure_generators/plus_signs_generator.rb +24 -18
- data/lib/geo_pattern/structure_generators/sine_waves_generator.rb +17 -15
- data/lib/geo_pattern/structure_generators/squares_generator.rb +10 -9
- data/lib/geo_pattern/structure_generators/tessellation_generator.rb +36 -34
- data/lib/geo_pattern/structure_generators/triangles_generator.rb +22 -19
- data/lib/geo_pattern/structure_generators/xes_generator.rb +26 -19
- data/lib/geo_pattern/svg_image.rb +10 -8
- data/lib/geo_pattern/version.rb +3 -1
- data/lib/geo_pattern.rb +53 -51
- data/script/console +4 -3
- data/spec/background_generators/solid_generator_spec.rb +16 -14
- data/spec/background_spec.rb +13 -11
- data/spec/color_generators/base_color_generator_spec.rb +10 -8
- data/spec/color_generators/simple_generator_spec.rb +5 -3
- data/spec/color_preset_spec.rb +17 -15
- data/spec/color_spec.rb +8 -6
- data/spec/geo_pattern_spec.rb +59 -58
- data/spec/helpers_spec.rb +30 -28
- data/spec/pattern_preset_spec.rb +15 -13
- data/spec/pattern_sieve_spec.rb +13 -11
- data/spec/pattern_spec.rb +20 -18
- data/spec/pattern_store_spec.rb +21 -19
- data/spec/pattern_validator_spec.rb +11 -9
- data/spec/seed_spec.rb +6 -4
- data/spec/spec_helper.rb +9 -8
- data/spec/structure_generators/chevrons_generator_spec.rb +4 -2
- data/spec/structure_generators/concentric_circles_generator_spec.rb +4 -2
- data/spec/structure_generators/diamonds_generator_spec.rb +4 -2
- data/spec/structure_generators/hexagons_generator_spec.rb +4 -2
- data/spec/structure_generators/mosaic_squares_generator_spec.rb +4 -2
- data/spec/structure_generators/nested_squares_generator_spec.rb +4 -2
- data/spec/structure_generators/octagons_generator_spec.rb +4 -2
- data/spec/structure_generators/overlapping_circles_generator_spec.rb +4 -2
- data/spec/structure_generators/overlapping_rings_generator_spec.rb +4 -2
- data/spec/structure_generators/plaid_generator_spec.rb +4 -2
- data/spec/structure_generators/plus_signs_generator_spec.rb +4 -2
- data/spec/structure_generators/sine_waves_generator_spec.rb +4 -2
- data/spec/structure_generators/squares_generator_spec.rb +4 -2
- data/spec/structure_generators/tessellation_generator_spec.rb +4 -2
- data/spec/structure_generators/triangles_generator_spec.rb +4 -2
- data/spec/structure_generators/xes_generator_spec.rb +4 -2
- data/spec/structure_spec.rb +18 -16
- data/spec/support/aruba.rb +6 -6
- data/spec/support/helpers/fixtures.rb +3 -1
- data/spec/support/kernel.rb +8 -2
- data/spec/support/matchers/image.rb +4 -2
- data/spec/support/matchers/name.rb +3 -1
- data/spec/support/rspec.rb +4 -2
- data/spec/support/shared_examples/generator.rb +12 -10
- data/spec/support/shared_examples/pattern.rb +7 -5
- data/spec/support/shared_examples/pattern_name.rb +4 -2
- data/spec/support/shared_examples/structure.rb +12 -10
- data/spec/support/string.rb +3 -2
- data/spec/svg_spec.rb +5 -3
- metadata +11 -59
- data/.rubocop.yml +0 -71
- 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
|
11
|
+
@scale = hex_val(0, 1)
|
10
12
|
@side_length = map(scale, 0, 15, 8, 60)
|
11
|
-
@hex_height
|
12
|
-
@hex_width
|
13
|
-
@hex
|
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
|
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
|
-
|
22
|
-
|
23
|
-
val
|
24
|
-
dy
|
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
|
28
|
+
fill = fill_color(val)
|
27
29
|
|
28
30
|
styles = {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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(
|
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
|
39
|
-
svg.polyline(hex, styles.merge(
|
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
|
44
|
-
dy = x % 2 == 0 ? 6 * hex_height : 6 * hex_height + hex_height / 2
|
45
|
-
svg.polyline(hex, styles.merge(
|
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(
|
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(
|
60
|
-
c =
|
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
|
-
|
17
|
-
|
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
|
-
|
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
|
41
|
-
fill
|
42
|
-
styles
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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(
|
49
|
-
svg.polyline(triangle, styles.merge(
|
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
|
53
|
-
styles
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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(
|
60
|
-
svg.polyline(triangle, styles.merge(
|
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
|
65
|
-
fill
|
64
|
+
opacity = opacity(val)
|
65
|
+
fill = fill_color(val)
|
66
66
|
triangle = build_right_triangle_shape(triangle_size)
|
67
|
-
styles
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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(
|
75
|
-
svg.polyline(triangle, styles.merge(
|
76
|
-
svg.polyline(triangle, styles.merge(
|
77
|
-
svg.polyline(triangle, styles.merge(
|
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
|
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
|
-
|
18
|
-
|
19
|
-
val
|
19
|
+
6.times do |y|
|
20
|
+
6.times do |x|
|
21
|
+
val = hex_val(i, 1)
|
20
22
|
opacity = opacity(val)
|
21
|
-
fill
|
23
|
+
fill = fill_color(val)
|
22
24
|
|
23
25
|
styles = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
34
|
-
|
35
|
+
y * square_size + y * block_size * 2 + block_size / 2,
|
36
|
+
square_size, square_size, styles)
|
35
37
|
|
36
|
-
val
|
38
|
+
val = hex_val(39 - i, 1)
|
37
39
|
opacity = opacity(val)
|
38
|
-
fill
|
40
|
+
fill = fill_color(val)
|
39
41
|
|
40
42
|
styles = {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
51
|
-
|
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
|
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
|
-
|
18
|
-
|
19
|
-
val
|
19
|
+
6.times do |y|
|
20
|
+
6.times do |x|
|
21
|
+
val = hex_val(i, 1)
|
20
22
|
opacity = opacity(val)
|
21
|
-
fill
|
23
|
+
fill = fill_color(val)
|
22
24
|
|
23
25
|
svg.polyline(tile,
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
11
|
+
@scale = hex_val(0, 1)
|
10
12
|
@diameter = map(scale, 0, 15, 25, 200)
|
11
|
-
@radius
|
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
|
-
|
19
|
-
|
20
|
-
val
|
20
|
+
6.times do |y|
|
21
|
+
6.times do |x|
|
22
|
+
val = hex_val(i, 1)
|
21
23
|
opacity = opacity(val)
|
22
|
-
fill
|
24
|
+
fill = fill_color(val)
|
23
25
|
|
24
26
|
styles = {
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
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
|
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
|
10
|
-
@ring_size
|
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
|
-
|
19
|
-
|
20
|
-
val
|
20
|
+
6.times do |y|
|
21
|
+
6.times do |x|
|
22
|
+
val = hex_val(i, 1)
|
21
23
|
opacity = opacity(val)
|
22
|
-
fill
|
24
|
+
fill = fill_color(val)
|
23
25
|
|
24
26
|
styles = {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
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
|
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
|
10
|
+
local_width = 0
|
9
11
|
|
10
12
|
# horizontal stripes
|
11
13
|
i = 0
|
12
14
|
18.times do
|
13
|
-
space
|
15
|
+
space = hex_val(i, 1)
|
14
16
|
local_height += space + 5
|
15
17
|
|
16
|
-
val
|
17
|
-
opacity
|
18
|
-
fill
|
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,
|
22
|
-
|
23
|
-
|
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
|
33
|
+
space = hex_val(i, 1)
|
33
34
|
local_width += space + 5
|
34
35
|
|
35
|
-
val
|
36
|
-
opacity
|
37
|
-
fill
|
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,
|
41
|
-
|
42
|
-
|
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
|
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
|
11
|
-
@plus_shape
|
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
|
-
|
19
|
-
|
20
|
-
val
|
20
|
+
6.times do |y|
|
21
|
+
6.times do |x|
|
22
|
+
val = hex_val(i, 1)
|
21
23
|
opacity = opacity(val)
|
22
|
-
fill
|
23
|
-
dx
|
24
|
+
fill = fill_color(val)
|
25
|
+
dx = (y % 2 == 0) ? 0 : 1
|
24
26
|
|
25
27
|
styles = {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
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
|
41
|
+
if x == 0
|
39
42
|
svg.group(plus_shape, styles.merge(
|
40
|
-
|
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
|
48
|
+
if y == 0
|
45
49
|
svg.group(plus_shape, styles.merge(
|
46
|
-
|
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
|
-
|
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
|
10
|
-
@amplitude
|
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
|
16
|
+
self.width = period
|
15
17
|
end
|
16
18
|
|
17
19
|
def generate_structure
|
18
|
-
|
19
|
-
val
|
20
|
-
opacity
|
21
|
-
fill
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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 =
|
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(
|
36
|
-
svg.path(str, styles.merge(
|
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
|