geo_pattern 1.3.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +30 -0
  3. data/.gitignore +1 -0
  4. data/.simplecov +26 -0
  5. data/Gemfile +17 -17
  6. data/README.md +154 -29
  7. data/Rakefile +72 -13
  8. data/fixtures/generated_patterns/chevrons.svg +1 -0
  9. data/fixtures/generated_patterns/concentric_circles.svg +1 -0
  10. data/fixtures/generated_patterns/diamonds.svg +1 -0
  11. data/fixtures/generated_patterns/diamonds_with_base_color.svg +1 -0
  12. data/fixtures/generated_patterns/diamonds_with_color.svg +1 -0
  13. data/fixtures/generated_patterns/hexagons.svg +1 -0
  14. data/fixtures/generated_patterns/mosaic_squares.svg +1 -0
  15. data/fixtures/generated_patterns/nested_squares.svg +1 -0
  16. data/fixtures/generated_patterns/octagons.svg +1 -0
  17. data/fixtures/generated_patterns/overlapping_circles.svg +1 -0
  18. data/fixtures/generated_patterns/overlapping_rings.svg +1 -0
  19. data/fixtures/generated_patterns/plaid.svg +1 -0
  20. data/fixtures/generated_patterns/plus_signs.svg +1 -0
  21. data/fixtures/generated_patterns/sine_waves.svg +1 -0
  22. data/fixtures/generated_patterns/squares.svg +1 -0
  23. data/fixtures/generated_patterns/tessellation.svg +1 -0
  24. data/fixtures/generated_patterns/triangles.svg +1 -0
  25. data/fixtures/generated_patterns/xes.svg +1 -0
  26. data/geo_pattern.gemspec +19 -17
  27. data/lib/geo_pattern/background.rb +27 -0
  28. data/lib/geo_pattern/background_generators/solid_generator.rb +54 -0
  29. data/lib/geo_pattern/color.rb +27 -0
  30. data/lib/geo_pattern/color_generators/base_color_generator.rb +57 -0
  31. data/lib/geo_pattern/color_generators/simple_generator.rb +29 -0
  32. data/lib/geo_pattern/color_preset.rb +32 -0
  33. data/lib/geo_pattern/errors.rb +9 -0
  34. data/lib/geo_pattern/geo_pattern_task.rb +61 -0
  35. data/lib/geo_pattern/helpers.rb +50 -1
  36. data/lib/geo_pattern/pattern.rb +86 -0
  37. data/lib/geo_pattern/pattern_generator.rb +34 -81
  38. data/lib/geo_pattern/pattern_helpers.rb +34 -2
  39. data/lib/geo_pattern/pattern_preset.rb +25 -0
  40. data/lib/geo_pattern/pattern_sieve.rb +38 -0
  41. data/lib/geo_pattern/pattern_store.rb +65 -0
  42. data/lib/geo_pattern/pattern_validator.rb +29 -0
  43. data/lib/geo_pattern/rake_task.rb +112 -0
  44. data/lib/geo_pattern/roles/comparable_metadata.rb +37 -0
  45. data/lib/geo_pattern/roles/named_generator.rb +15 -0
  46. data/lib/geo_pattern/seed.rb +23 -0
  47. data/lib/geo_pattern/structure.rb +27 -0
  48. data/lib/geo_pattern/structure_generators/base_generator.rb +88 -0
  49. data/lib/geo_pattern/structure_generators/chevrons_generator.rb +57 -0
  50. data/lib/geo_pattern/structure_generators/concentric_circles_generator.rb +58 -0
  51. data/lib/geo_pattern/structure_generators/diamonds_generator.rb +72 -0
  52. data/lib/geo_pattern/structure_generators/hexagons_generator.rb +69 -0
  53. data/lib/geo_pattern/structure_generators/mosaic_squares_generator.rb +85 -0
  54. data/lib/geo_pattern/structure_generators/nested_squares_generator.rb +62 -0
  55. data/lib/geo_pattern/structure_generators/octagons_generator.rb +45 -0
  56. data/lib/geo_pattern/structure_generators/overlapping_circles_generator.rb +57 -0
  57. data/lib/geo_pattern/structure_generators/overlapping_rings_generator.rb +57 -0
  58. data/lib/geo_pattern/structure_generators/plaid_generator.rb +55 -0
  59. data/lib/geo_pattern/structure_generators/plus_signs_generator.rb +68 -0
  60. data/lib/geo_pattern/structure_generators/sine_waves_generator.rb +45 -0
  61. data/lib/geo_pattern/structure_generators/squares_generator.rb +37 -0
  62. data/lib/geo_pattern/structure_generators/tessellation_generator.rb +105 -0
  63. data/lib/geo_pattern/structure_generators/triangles_generator.rb +64 -0
  64. data/lib/geo_pattern/structure_generators/xes_generator.rb +74 -0
  65. data/lib/geo_pattern/svg_image.rb +103 -0
  66. data/lib/geo_pattern/version.rb +3 -1
  67. data/lib/geo_pattern.rb +54 -30
  68. data/script/bootstrap +30 -0
  69. data/script/console +9 -0
  70. data/script/test +21 -0
  71. data/spec/background_generators/solid_generator_spec.rb +52 -0
  72. data/spec/background_spec.rb +27 -0
  73. data/spec/color_generators/base_color_generator_spec.rb +33 -0
  74. data/spec/color_generators/simple_generator_spec.rb +14 -0
  75. data/spec/color_preset_spec.rb +55 -0
  76. data/spec/color_spec.rb +17 -0
  77. data/spec/geo_pattern_spec.rb +98 -26
  78. data/spec/helpers_spec.rb +67 -0
  79. data/spec/pattern_preset_spec.rb +43 -0
  80. data/spec/pattern_sieve_spec.rb +68 -0
  81. data/spec/pattern_spec.rb +74 -0
  82. data/spec/pattern_store_spec.rb +49 -0
  83. data/spec/pattern_validator_spec.rb +30 -0
  84. data/spec/seed_spec.rb +16 -0
  85. data/spec/spec_helper.rb +9 -13
  86. data/spec/structure_generators/chevrons_generator_spec.rb +7 -0
  87. data/spec/structure_generators/concentric_circles_generator_spec.rb +7 -0
  88. data/spec/structure_generators/diamonds_generator_spec.rb +7 -0
  89. data/spec/structure_generators/hexagons_generator_spec.rb +7 -0
  90. data/spec/structure_generators/mosaic_squares_generator_spec.rb +7 -0
  91. data/spec/structure_generators/nested_squares_generator_spec.rb +7 -0
  92. data/spec/structure_generators/octagons_generator_spec.rb +7 -0
  93. data/spec/structure_generators/overlapping_circles_generator_spec.rb +7 -0
  94. data/spec/structure_generators/overlapping_rings_generator_spec.rb +7 -0
  95. data/spec/structure_generators/plaid_generator_spec.rb +7 -0
  96. data/spec/structure_generators/plus_signs_generator_spec.rb +7 -0
  97. data/spec/structure_generators/sine_waves_generator_spec.rb +7 -0
  98. data/spec/structure_generators/squares_generator_spec.rb +7 -0
  99. data/spec/structure_generators/tessellation_generator_spec.rb +7 -0
  100. data/spec/structure_generators/triangles_generator_spec.rb +7 -0
  101. data/spec/structure_generators/xes_generator_spec.rb +7 -0
  102. data/spec/structure_spec.rb +40 -0
  103. data/spec/support/aruba.rb +6 -6
  104. data/spec/support/helpers/fixtures.rb +14 -0
  105. data/spec/support/kernel.rb +46 -0
  106. data/spec/support/matchers/image.rb +19 -0
  107. data/spec/support/matchers/name.rb +17 -0
  108. data/spec/support/rspec.rb +4 -2
  109. data/spec/support/shared_examples/generator.rb +48 -0
  110. data/spec/support/shared_examples/pattern.rb +33 -0
  111. data/spec/support/shared_examples/pattern_name.rb +9 -0
  112. data/spec/support/shared_examples/structure.rb +50 -0
  113. data/spec/support/string.rb +3 -2
  114. data/spec/svg_spec.rb +8 -6
  115. metadata +105 -37
  116. data/.rubocop.yml +0 -13
  117. data/lib/geo_pattern/pattern/base_pattern.rb +0 -47
  118. data/lib/geo_pattern/pattern/chevron_pattern.rb +0 -45
  119. data/lib/geo_pattern/pattern/concentric_circles_pattern.rb +0 -47
  120. data/lib/geo_pattern/pattern/diamond_pattern.rb +0 -56
  121. data/lib/geo_pattern/pattern/hexagon_pattern.rb +0 -57
  122. data/lib/geo_pattern/pattern/mosaic_squares_pattern.rb +0 -76
  123. data/lib/geo_pattern/pattern/nested_squares_pattern.rb +0 -51
  124. data/lib/geo_pattern/pattern/octagon_pattern.rb +0 -35
  125. data/lib/geo_pattern/pattern/overlapping_circles_pattern.rb +0 -46
  126. data/lib/geo_pattern/pattern/overlapping_rings_pattern.rb +0 -46
  127. data/lib/geo_pattern/pattern/plaid_pattern.rb +0 -49
  128. data/lib/geo_pattern/pattern/plus_sign_pattern.rb +0 -53
  129. data/lib/geo_pattern/pattern/sine_wave_pattern.rb +0 -36
  130. data/lib/geo_pattern/pattern/square_pattern.rb +0 -27
  131. data/lib/geo_pattern/pattern/tessellation_pattern.rb +0 -93
  132. data/lib/geo_pattern/pattern/triangle_pattern.rb +0 -51
  133. data/lib/geo_pattern/pattern/xes_pattern.rb +0 -58
  134. data/lib/geo_pattern/svg.rb +0 -77
  135. data/spec/support/helpers.rb +0 -34
@@ -1,47 +0,0 @@
1
- module GeoPattern
2
- class BasePattern < Struct.new(:svg, :hash)
3
- FILL_COLOR_DARK = "#222"
4
- FILL_COLOR_LIGHT = "#ddd"
5
- STROKE_COLOR = "#000"
6
- STROKE_OPACITY = 0.02
7
- OPACITY_MIN = 0.02
8
- OPACITY_MAX = 0.15
9
-
10
- # Public: mutate the given `svg` object with a rendered pattern
11
- #
12
- # Note: this method _must_ be implemented by sub-
13
- # classes.
14
- #
15
- # svg - the SVG container
16
- #
17
- # Returns a reference to the same `svg` object
18
- # only this time with more patterns.
19
- def render_to_svg
20
- raise NotImplementedError
21
- end
22
-
23
- def hex_val(index, len)
24
- PatternHelpers.hex_val(hash, index, len)
25
- end
26
-
27
- def fill_color(val)
28
- (val.even?) ? FILL_COLOR_LIGHT : FILL_COLOR_DARK
29
- end
30
-
31
- def opacity(val)
32
- map(val, 0, 15, OPACITY_MIN, OPACITY_MAX)
33
- end
34
-
35
- def map(value, v_min, v_max, d_min, d_max)
36
- PatternHelpers.map(value, v_min, v_max, d_min, d_max)
37
- end
38
-
39
- protected
40
- def build_plus_shape(square_size)
41
- [
42
- "rect(#{square_size},0,#{square_size},#{square_size * 3})",
43
- "rect(0, #{square_size},#{square_size * 3},#{square_size})"
44
- ]
45
- end
46
- end
47
- end
@@ -1,45 +0,0 @@
1
- module GeoPattern
2
- class ChevronPattern < BasePattern
3
- def render_to_svg
4
- chevron_width = map(hex_val(0, 1), 0, 15, 30, 80)
5
- chevron_height = map(hex_val(0, 1), 0, 15, 30, 80)
6
- chevron = build_chevron_shape(chevron_width, chevron_height)
7
-
8
- svg.set_width(chevron_width * 6)
9
- svg.set_height(chevron_height * 6 * 0.66)
10
-
11
- i = 0
12
- for y in 0..5
13
- for x in 0..5
14
- val = hex_val(i, 1)
15
- opacity = opacity(val)
16
- fill = fill_color(val)
17
-
18
- styles = {
19
- "stroke" => STROKE_COLOR,
20
- "stroke-opacity" => STROKE_OPACITY,
21
- "fill" => fill,
22
- "fill-opacity" => opacity,
23
- "stroke-width" => 1
24
- }
25
-
26
- svg.group(chevron, styles.merge({"transform" => "translate(#{x*chevron_width},#{y*chevron_height*0.66 - chevron_height/2})"}))
27
-
28
- # Add an extra row at the end that matches the first row, for tiling.
29
- if (y == 0)
30
- svg.group(chevron, styles.merge({"transform" => "translate(#{x*chevron_width},#{6*chevron_height*0.66 - chevron_height/2})"}))
31
- end
32
- i += 1
33
- end
34
- end
35
- end
36
-
37
- def build_chevron_shape(width, height)
38
- e = height * 0.66
39
- [
40
- %Q{polyline("0,0,#{width/2},#{height-e},#{width/2},#{height},0,#{e},0,0")},
41
- %Q{polyline("#{width/2},#{height-e},#{width},0,#{width},#{e},#{width/2},#{height},#{width/2},#{height-e}")}
42
- ]
43
- end
44
- end
45
- end
@@ -1,47 +0,0 @@
1
- module GeoPattern
2
- class ConcentricCirclesPattern < BasePattern
3
- def render_to_svg
4
- scale = hex_val(0, 1)
5
- ring_size = map(scale, 0, 15, 10, 60)
6
- stroke_width = ring_size / 5
7
-
8
- svg.set_width((ring_size + stroke_width) * 6)
9
- svg.set_height((ring_size + stroke_width) * 6)
10
-
11
- i = 0
12
- for y in 0..5
13
- for x in 0..5
14
- val = hex_val(i, 1)
15
- opacity = opacity(val)
16
- fill = fill_color(val)
17
-
18
- svg.circle(
19
- x*ring_size + x*stroke_width + (ring_size + stroke_width)/2,
20
- y*ring_size + y*stroke_width + (ring_size + stroke_width)/2,
21
- ring_size/2, {
22
- "fill" => "none",
23
- "stroke" => fill,
24
- "style" => {
25
- "opacity" => opacity,
26
- "stroke-width" => "#{stroke_width}px"
27
- }
28
- })
29
-
30
- val = hex_val(39-i, 1)
31
- opacity = opacity(val)
32
- fill = fill_color(val)
33
-
34
- svg.circle(
35
- x*ring_size + x*stroke_width + (ring_size + stroke_width)/2,
36
- y*ring_size + y*stroke_width + (ring_size + stroke_width)/2,
37
- ring_size/4, {
38
- "fill" => fill,
39
- "fill-opacity" => opacity
40
- })
41
-
42
- i += 1
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,56 +0,0 @@
1
- module GeoPattern
2
- class DiamondPattern < BasePattern
3
- def render_to_svg
4
- diamond_width = map(hex_val(0, 1), 0, 15, 10, 50)
5
- diamond_height = map(hex_val(1, 1), 0, 15, 10, 50)
6
- diamond = build_diamond_shape(diamond_width, diamond_height)
7
-
8
- svg.set_width(diamond_width * 6)
9
- svg.set_height(diamond_height * 3)
10
-
11
- i = 0
12
- for y in 0..5
13
- for x in 0..5
14
- val = hex_val(i, 1)
15
- opacity = opacity(val)
16
- fill = fill_color(val)
17
-
18
- styles = {
19
- "fill" => fill,
20
- "fill-opacity" => opacity,
21
- "stroke" => STROKE_COLOR,
22
- "stroke-opacity" => STROKE_OPACITY
23
- }
24
-
25
- dx = (y % 2 == 0) ? 0 : diamond_width / 2
26
-
27
- svg.polyline(diamond, styles.merge({
28
- "transform" => "translate(#{x*diamond_width - diamond_width/2 + dx}, #{diamond_height/2*y - diamond_height/2})"}))
29
-
30
- # Add an extra one at top-right, for tiling.
31
- if (x == 0)
32
- svg.polyline(diamond, styles.merge({
33
- "transform" => "translate(#{6*diamond_width - diamond_width/2 + dx}, #{diamond_height/2*y - diamond_height/2})"}))
34
- end
35
-
36
- # Add an extra row at the end that matches the first row, for tiling.
37
- if (y == 0)
38
- svg.polyline(diamond, styles.merge({
39
- "transform" => "translate(#{x*diamond_width - diamond_width/2 + dx}, #{diamond_height/2*6 - diamond_height/2})"}))
40
- end
41
-
42
- # Add an extra one at bottom-right, for tiling.
43
- if (x == 0 and y == 0)
44
- svg.polyline(diamond, styles.merge({
45
- "transform" => "translate(#{6*diamond_width - diamond_width/2 + dx}, #{diamond_height/2*6 - diamond_height/2})"}))
46
- end
47
- i += 1
48
- end
49
- end
50
- end
51
-
52
- def build_diamond_shape(width, height)
53
- "#{width/2}, 0, #{width}, #{height/2}, #{width/2}, #{height}, 0, #{height/2}"
54
- end
55
- end
56
- end
@@ -1,57 +0,0 @@
1
- module GeoPattern
2
- class HexagonPattern < BasePattern
3
- def render_to_svg
4
- scale = hex_val(0, 1)
5
- side_length = map(scale, 0, 15, 8, 60)
6
- hex_height = side_length * Math.sqrt(3)
7
- hex_width = side_length * 2
8
- hex = build_hexagon_shape(side_length)
9
-
10
- svg.set_width((hex_width * 3) + (side_length * 3))
11
- svg.set_height(hex_height * 6)
12
-
13
- i = 0
14
- for y in 0..5
15
- for x in 0..5
16
- val = hex_val(i, 1)
17
- dy = x % 2 == 0 ? y*hex_height : y*hex_height + hex_height/2
18
- opacity = opacity(val)
19
- fill = fill_color(val)
20
-
21
- styles = {
22
- "fill" => fill,
23
- "fill-opacity" => opacity,
24
- "stroke" => STROKE_COLOR,
25
- "stroke-opacity" => STROKE_OPACITY
26
- }
27
-
28
- svg.polyline(hex, styles.merge({"transform" => "translate(#{x*side_length*1.5 - hex_width/2}, #{dy - hex_height/2})"}))
29
-
30
- # Add an extra one at top-right, for tiling.
31
- if (x == 0)
32
- svg.polyline(hex, styles.merge({"transform" => "translate(#{6*side_length*1.5 - hex_width/2}, #{dy - hex_height/2})"}))
33
- end
34
-
35
- # Add an extra row at the end that matches the first row, for tiling.
36
- if (y == 0)
37
- dy = x % 2 == 0 ? 6*hex_height : 6*hex_height + hex_height/2;
38
- svg.polyline(hex, styles.merge({"transform" => "translate(#{x*side_length*1.5 - hex_width/2}, #{dy - hex_height/2})"}))
39
- end
40
-
41
- # Add an extra one at bottom-right, for tiling.
42
- if (x == 0 && y == 0)
43
- svg.polyline(hex, styles.merge({"transform" => "translate(#{6*side_length*1.5 - hex_width/2}, #{5*hex_height + hex_height/2})"}))
44
- end
45
- i += 1
46
- end
47
- end
48
- end
49
-
50
- def build_hexagon_shape(sideLength)
51
- c = sideLength
52
- a = c/2
53
- b = Math.sin(60 * Math::PI / 180)*c
54
- "0,#{b},#{a},0,#{a+c},0,#{2*c},#{b},#{a+c},#{2*b},#{a},#{2*b},0,#{b}"
55
- end
56
- end
57
- end
@@ -1,76 +0,0 @@
1
- module GeoPattern
2
- class MosaicSquaresPattern < BasePattern
3
- def render_to_svg
4
- triangle_size = map(hex_val(0, 1), 0, 15, 15, 50)
5
-
6
- svg.set_width(triangle_size * 8)
7
- svg.set_height(triangle_size * 8)
8
-
9
- i = 0
10
- for y in 0..3
11
- for x in 0..3
12
- if x.even?
13
- if y.even?
14
- draw_outer_mosaic_tile(x*triangle_size*2, y*triangle_size*2, triangle_size, hex_val(i, 1))
15
- else
16
- draw_inner_mosaic_tile(x*triangle_size*2, y*triangle_size*2, triangle_size, [hex_val(i, 1), hex_val(i+1, 1)])
17
- end
18
- else
19
- if y.even?
20
- draw_inner_mosaic_tile(x*triangle_size*2, y*triangle_size*2, triangle_size, [hex_val(i, 1), hex_val(i+1, 1)])
21
- else
22
- draw_outer_mosaic_tile(x*triangle_size*2, y*triangle_size*2, triangle_size, hex_val(i, 1))
23
- end
24
- end
25
- i += 1
26
- end
27
- end
28
- end
29
-
30
- def draw_inner_mosaic_tile(x, y, triangle_size, vals)
31
- triangle = build_right_triangle_shape(triangle_size)
32
- opacity = opacity(vals[0])
33
- fill = fill_color(vals[0])
34
- styles = {
35
- "stroke" => STROKE_COLOR,
36
- "stroke-opacity" => STROKE_OPACITY,
37
- "fill-opacity" => opacity,
38
- "fill" => fill
39
- }
40
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x+triangle_size}, #{y}) scale(-1, 1)"}))
41
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x+triangle_size}, #{y+triangle_size*2}) scale(1, -1)"}))
42
-
43
- opacity = opacity(vals[1])
44
- fill = fill_color(vals[1])
45
- styles = {
46
- "stroke" => STROKE_COLOR,
47
- "stroke-opacity" => STROKE_OPACITY,
48
- "fill-opacity" => opacity,
49
- "fill" => fill
50
- }
51
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x+triangle_size}, #{y+triangle_size*2}) scale(-1, -1)"}))
52
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x+triangle_size}, #{y}) scale(1, 1)"}))
53
- end
54
-
55
- def draw_outer_mosaic_tile(x, y, triangle_size, val)
56
- opacity = opacity(val)
57
- fill = fill_color(val)
58
- triangle = build_right_triangle_shape(triangle_size)
59
- styles = {
60
- "stroke" => STROKE_COLOR,
61
- "stroke-opacity" => STROKE_OPACITY,
62
- "fill-opacity" => opacity,
63
- "fill" => fill
64
- }
65
-
66
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x}, #{y+triangle_size}) scale(1, -1)"}))
67
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x+triangle_size*2}, #{y+triangle_size}) scale(-1, -1)"}))
68
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x}, #{y+triangle_size}) scale(1, 1)"}))
69
- svg.polyline(triangle, styles.merge({"transform" => "translate(#{x+triangle_size*2}, #{y+triangle_size}) scale(-1, 1)"}))
70
- end
71
-
72
- def build_right_triangle_shape(side_length)
73
- "0, 0, #{side_length}, #{side_length}, 0, #{side_length}, 0, 0"
74
- end
75
- end
76
- end
@@ -1,51 +0,0 @@
1
- module GeoPattern
2
- class NestedSquaresPattern < BasePattern
3
- def render_to_svg
4
- block_size = map(hex_val(0, 1), 0, 15, 4, 12)
5
- square_size = block_size * 7
6
-
7
- svg.set_width((square_size + block_size)*6 + block_size*6)
8
- svg.set_height((square_size + block_size)*6 + block_size*6)
9
-
10
- i = 0
11
- for y in 0..5
12
- for x in 0..5
13
- val = hex_val(i, 1)
14
- opacity = opacity(val)
15
- fill = fill_color(val)
16
-
17
- styles = {
18
- "fill" => "none",
19
- "stroke" => fill,
20
- "style" => {
21
- "opacity" => opacity,
22
- "stroke-width" => "#{block_size}px"
23
- }
24
- }
25
-
26
- svg.rect(x*square_size + x*block_size*2 + block_size/2,
27
- y*square_size + y*block_size*2 + block_size/2,
28
- square_size, square_size, styles)
29
-
30
- val = hex_val(39-i, 1)
31
- opacity = opacity(val)
32
- fill = fill_color(val)
33
-
34
- styles = {
35
- "fill" => "none",
36
- "stroke" => fill,
37
- "style" => {
38
- "opacity" => opacity,
39
- "stroke-width" => "#{block_size}px"
40
- }
41
- }
42
-
43
- svg.rect(x*square_size + x*block_size*2 + block_size/2 + block_size*2,
44
- y*square_size + y*block_size*2 + block_size/2 + block_size*2,
45
- block_size * 3, block_size * 3, styles)
46
- i += 1
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,35 +0,0 @@
1
- module GeoPattern
2
- class OctagonPattern < BasePattern
3
- def render_to_svg
4
- square_size = map(hex_val(0, 1), 0, 15, 10, 60)
5
- tile = build_octogon_shape(square_size)
6
-
7
- svg.set_width(square_size * 6)
8
- svg.set_height(square_size * 6)
9
-
10
- i = 0
11
- for y in 0..5
12
- for x in 0..5
13
- val = hex_val(i, 1)
14
- opacity = opacity(val)
15
- fill = fill_color(val)
16
-
17
- svg.polyline(tile, {
18
- "fill" => fill,
19
- "fill-opacity" => opacity,
20
- "stroke" => STROKE_COLOR,
21
- "stroke-opacity" => STROKE_OPACITY,
22
- "transform" => "translate(#{x*square_size}, #{y*square_size})"
23
- })
24
- i += 1
25
- end
26
- end
27
- end
28
-
29
- def build_octogon_shape(square_size)
30
- s = square_size
31
- c = s * 0.33
32
- "#{c},0,#{s-c},0,#{s},#{c},#{s},#{s-c},#{s-c},#{s},#{c},#{s},0,#{s-c},0,#{c},#{c},0"
33
- end
34
- end
35
- end
@@ -1,46 +0,0 @@
1
- module GeoPattern
2
- class OverlappingCirclesPattern < BasePattern
3
- def render_to_svg
4
- scale = hex_val(0, 1)
5
- diameter = map(scale, 0, 15, 25, 200)
6
- radius = diameter/2;
7
-
8
- svg.set_width(radius * 6)
9
- svg.set_height(radius * 6)
10
-
11
- i = 0
12
- for y in 0..5
13
- for x in 0..5
14
- val = hex_val(i, 1)
15
- opacity = opacity(val)
16
- fill = fill_color(val)
17
-
18
- styles = {
19
- "fill" => fill,
20
- "style" => {
21
- "opacity" => opacity
22
- }
23
- }
24
-
25
- svg.circle(x*radius, y*radius, radius, styles)
26
-
27
- # Add an extra one at top-right, for tiling.
28
- if (x == 0)
29
- svg.circle(6*radius, y*radius, radius, styles)
30
- end
31
-
32
- # Add an extra row at the end that matches the first row, for tiling.
33
- if (y == 0)
34
- svg.circle(x*radius, 6*radius, radius, styles)
35
- end
36
-
37
- # Add an extra one at bottom-right, for tiling.
38
- if (x == 0 and y == 0)
39
- svg.circle(6*radius, 6*radius, radius, styles)
40
- end
41
- i += 1
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,46 +0,0 @@
1
- module GeoPattern
2
- class OverlappingRingsPattern < BasePattern
3
- def render_to_svg
4
- scale = hex_val(0, 1)
5
- ring_size = map(scale, 0, 15, 10, 60)
6
- stroke_width = ring_size / 4
7
-
8
- svg.set_width(ring_size * 6)
9
- svg.set_height(ring_size * 6)
10
-
11
- i = 0
12
- for y in 0..5
13
- for x in 0..5
14
- val = hex_val(i, 1)
15
- opacity = opacity(val)
16
- fill = fill_color(val)
17
-
18
- styles = {
19
- "fill" => "none",
20
- "stroke" => fill,
21
- "style" => {
22
- "opacity" => opacity,
23
- "stroke-width" => "#{stroke_width}px"
24
- }
25
- }
26
-
27
- svg.circle(x*ring_size, y*ring_size, ring_size - stroke_width/2, styles)
28
-
29
- # Add an extra one at top-right, for tiling.
30
- if (x == 0)
31
- svg.circle(6*ring_size, y*ring_size, ring_size - stroke_width/2, styles)
32
- end
33
-
34
- if (y == 0)
35
- svg.circle(x*ring_size, 6*ring_size, ring_size - stroke_width/2, styles)
36
- end
37
-
38
- if (x == 0 and y == 0)
39
- svg.circle(6*ring_size, 6*ring_size, ring_size - stroke_width/2, styles)
40
- end
41
- i += 1
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,49 +0,0 @@
1
- module GeoPattern
2
- class PlaidPattern < BasePattern
3
- def render_to_svg
4
- height = 0
5
- width = 0
6
-
7
- # horizontal stripes
8
- i = 0
9
- 18.times do
10
- space = hex_val(i, 1)
11
- height += space + 5
12
-
13
- val = hex_val(i+1, 1)
14
- opacity = opacity(val)
15
- fill = fill_color(val)
16
- stripe_height = val + 5
17
-
18
- svg.rect(0, height, "100%", stripe_height, {
19
- "opacity" => opacity,
20
- "fill" => fill
21
- })
22
- height += stripe_height
23
- i += 2
24
- end
25
-
26
- # vertical stripes
27
- i = 0
28
- 18.times do
29
- space = hex_val(i, 1)
30
- width += space + 5
31
-
32
- val = hex_val(i+1, 1)
33
- opacity = opacity(val)
34
- fill = fill_color(val)
35
- stripe_width = val + 5
36
-
37
- svg.rect(width, 0, stripe_width, "100%", {
38
- "opacity" => opacity,
39
- "fill" => fill
40
- })
41
- width += stripe_width
42
- i += 2
43
- end
44
-
45
- svg.set_width(width)
46
- svg.set_height(height)
47
- end
48
- end
49
- end
@@ -1,53 +0,0 @@
1
- module GeoPattern
2
- class PlusSignPattern < BasePattern
3
- def render_to_svg
4
- square_size = map(hex_val(0, 1), 0, 15, 10, 25)
5
- plus_size = square_size * 3
6
- plus_shape = build_plus_shape(square_size)
7
-
8
- svg.set_width(square_size * 12)
9
- svg.set_height(square_size * 12)
10
-
11
- i = 0
12
- for y in 0..5
13
- for x in 0..5
14
- val = hex_val(i, 1)
15
- opacity = opacity(val)
16
- fill = fill_color(val)
17
- dx = (y % 2 == 0) ? 0 : 1
18
-
19
- styles = {
20
- "fill" => fill,
21
- "stroke" => STROKE_COLOR,
22
- "stroke-opacity" => STROKE_OPACITY,
23
- "style" => {
24
- "fill-opacity" => opacity
25
- }
26
- }
27
-
28
- svg.group(plus_shape, styles.merge({
29
- "transform" => "translate(#{x*plus_size - x*square_size + dx*square_size - square_size},#{y*plus_size - y*square_size - plus_size/2})"}))
30
-
31
- # Add an extra column on the right for tiling.
32
- if (x == 0)
33
- svg.group(plus_shape, styles.merge({
34
- "transform" => "translate(#{4*plus_size - x*square_size + dx*square_size - square_size},#{y*plus_size - y*square_size - plus_size/2})"}))
35
- end
36
-
37
- # Add an extra row on the bottom that matches the first row, for tiling.
38
- if (y == 0)
39
- svg.group(plus_shape, styles.merge({
40
- "transform" => "translate(#{x*plus_size - x*square_size + dx*square_size - square_size},#{4*plus_size - y*square_size - plus_size/2})"}))
41
- end
42
-
43
- # Add an extra one at top-right and bottom-right, for tiling.
44
- if (x == 0 && y == 0)
45
- svg.group(plus_shape, styles.merge({
46
- "transform" => "translate(#{4*plus_size - x*square_size + dx*square_size - square_size},#{4*plus_size - y*square_size - plus_size/2})"}))
47
- end
48
- i += 1
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,36 +0,0 @@
1
- module GeoPattern
2
- class SineWavePattern < BasePattern
3
- def render_to_svg
4
- period = map(hex_val(0, 1), 0, 15, 100, 400).floor
5
- amplitude = map(hex_val(1, 1), 0, 15, 30, 100).floor
6
- wave_width = map(hex_val(2, 1), 0, 15, 3, 30).floor
7
-
8
- svg.set_width(period)
9
- svg.set_height(wave_width * 36)
10
-
11
- for i in 0..35
12
- val = hex_val(i, 1)
13
- opacity = opacity(val)
14
- fill = fill_color(val)
15
- x_offset = period / 4 * 0.7
16
-
17
- styles = {
18
- "fill" => "none",
19
- "stroke" => fill,
20
- "style" => {
21
- "opacity" => opacity,
22
- "stroke-width" => "#{wave_width}px"
23
- }
24
- }
25
-
26
- str = "M0 "+amplitude.to_s+
27
- " C "+x_offset.to_s+" 0, "+(period/2 - x_offset).to_s+" 0, "+(period/2).to_s+" "+amplitude.to_s+
28
- " S "+(period-x_offset).to_s+" "+(amplitude*2).to_s+", "+period.to_s+" "+amplitude.to_s+
29
- " S "+(period*1.5-x_offset).to_s+" 0, "+(period*1.5).to_s+", "+amplitude.to_s;
30
-
31
- svg.path(str, styles.merge({"transform" => "translate(-#{period/4}, #{wave_width*i-amplitude*1.5})"}))
32
- svg.path(str, styles.merge({"transform" => "translate(-#{period/4}, #{wave_width*i-amplitude*1.5 + wave_width*36})"}))
33
- end
34
- end
35
- end
36
- end
@@ -1,27 +0,0 @@
1
- module GeoPattern
2
- class SquarePattern < BasePattern
3
- def render_to_svg
4
- square_size = map(hex_val(0, 1), 0, 15, 10, 60)
5
-
6
- svg.set_width(square_size * 6)
7
- svg.set_height(square_size * 6)
8
-
9
- i = 0
10
- for y in 0..5
11
- for x in 0..5
12
- val = hex_val(i, 1)
13
- opacity = opacity(val)
14
- fill = fill_color(val)
15
-
16
- svg.rect(x*square_size, y*square_size, square_size, square_size, {
17
- "fill" => fill,
18
- "fill-opacity" => opacity,
19
- "stroke" => STROKE_COLOR,
20
- "stroke-opacity" => STROKE_OPACITY
21
- })
22
- i += 1
23
- end
24
- end
25
- end
26
- end
27
- end