Class: GeoPattern::NestedSquaresPattern

Inherits:
BasePattern
  • Object
show all
Defined in:
lib/geo_pattern/pattern/nested_squares_pattern.rb

Constant Summary

Constants inherited from BasePattern

BasePattern::FILL_COLOR_DARK, BasePattern::FILL_COLOR_LIGHT, BasePattern::OPACITY_MAX, BasePattern::OPACITY_MIN, BasePattern::STROKE_COLOR, BasePattern::STROKE_OPACITY

Instance Attribute Summary

Attributes inherited from BasePattern

#hash, #svg

Instance Method Summary collapse

Methods inherited from BasePattern

#fill_color, #hex_val, #map, #opacity

Instance Method Details

#render_to_svgObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/geo_pattern/pattern/nested_squares_pattern.rb', line 3

def render_to_svg
  block_size = map(hex_val(0, 1), 0, 15, 4, 12)
  square_size = block_size * 7

  svg.set_width((square_size + block_size)*6 + block_size*6)
  svg.set_height((square_size + block_size)*6 + block_size*6)

  i = 0
  for y in 0..5
    for x in 0..5
      val     = hex_val(i, 1)
      opacity = opacity(val)
      fill    = fill_color(val)

      styles = {
        "fill"   => "none",
        "stroke" => fill,
        "style"  => {
          "opacity" => opacity,
          "stroke-width" => "#{block_size}px"
        }
      }

      svg.rect(x*square_size + x*block_size*2 + block_size/2,
                y*square_size + y*block_size*2 + block_size/2,
                square_size, square_size, styles)

      val     = hex_val(39-i, 1)
      opacity = opacity(val)
      fill    = fill_color(val)

      styles = {
        "fill"   => "none",
        "stroke" => fill,
        "style"  => {
          "opacity" => opacity,
          "stroke-width" => "#{block_size}px"
        }
      }

      svg.rect(x*square_size + x*block_size*2 + block_size/2 + block_size*2,
                y*square_size + y*block_size*2 + block_size/2 + block_size*2,
                block_size * 3, block_size * 3, styles)
      i += 1
    end
  end
end