Class: GeoPattern::BasePattern

Inherits:
Struct
  • Object
show all
Defined in:
lib/geo_pattern/pattern/base_pattern.rb

Constant Summary collapse

FILL_COLOR_DARK =
"#222"
FILL_COLOR_LIGHT =
"#ddd"
STROKE_COLOR =
"#000"
STROKE_OPACITY =
0.02
OPACITY_MIN =
0.02
OPACITY_MAX =
0.15

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hashObject

Returns the value of attribute hash

Returns:

  • (Object)

    the current value of hash



2
3
4
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 2

def hash
  @hash
end

#svgObject

Returns the value of attribute svg

Returns:

  • (Object)

    the current value of svg



2
3
4
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 2

def svg
  @svg
end

Instance Method Details

#fill_color(val) ⇒ Object



27
28
29
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 27

def fill_color(val)
  (val.even?) ? FILL_COLOR_LIGHT : FILL_COLOR_DARK
end

#hex_val(index, len) ⇒ Object



23
24
25
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 23

def hex_val(index, len)
  PatternHelpers.hex_val(hash, index, len)
end

#map(value, v_min, v_max, d_min, d_max) ⇒ Object



35
36
37
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 35

def map(value, v_min, v_max, d_min, d_max)
  PatternHelpers.map(value, v_min, v_max, d_min, d_max)
end

#opacity(val) ⇒ Object



31
32
33
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 31

def opacity(val)
  map(val, 0, 15, OPACITY_MIN, OPACITY_MAX)
end

#render_to_svgObject

Public: mutate the given ‘svg` object with a rendered pattern

Note: this method must be implemented by sub- classes.

svg - the SVG container

Returns a reference to the same ‘svg` object only this time with more patterns.

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/geo_pattern/pattern/base_pattern.rb', line 19

def render_to_svg
  raise NotImplementedError
end