Class: GeoPattern::PlusSignPattern
- Inherits:
-
BasePattern
- Object
- Struct
- BasePattern
- GeoPattern::PlusSignPattern
- Defined in:
- lib/geo_pattern/pattern/plus_sign_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
Instance Method Summary collapse
Methods inherited from BasePattern
#fill_color, #hex_val, #map, #opacity
Instance Method Details
#render_to_svg ⇒ Object
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 50 51 |
# File 'lib/geo_pattern/pattern/plus_sign_pattern.rb', line 3 def render_to_svg square_size = map(hex_val(0, 1), 0, 15, 10, 25) plus_size = square_size * 3 plus_shape = build_plus_shape(square_size) svg.set_width(square_size * 12) svg.set_height(square_size * 12) i = 0 for y in 0..5 for x in 0..5 val = hex_val(i, 1) opacity = opacity(val) fill = fill_color(val) dx = (y % 2 == 0) ? 0 : 1 styles = { "fill" => fill, "stroke" => STROKE_COLOR, "stroke-opacity" => STROKE_OPACITY, "style" => { "fill-opacity" => opacity } } svg.group(plus_shape, styles.merge({ "transform" => "translate(#{x*plus_size - x*square_size + dx*square_size - square_size},#{y*plus_size - y*square_size - plus_size/2})"})) # Add an extra column on the right for tiling. if (x == 0) svg.group(plus_shape, styles.merge({ "transform" => "translate(#{4*plus_size - x*square_size + dx*square_size - square_size},#{y*plus_size - y*square_size - plus_size/2})"})) end # Add an extra row on the bottom that matches the first row, for tiling. if (y == 0) svg.group(plus_shape, styles.merge({ "transform" => "translate(#{x*plus_size - x*square_size + dx*square_size - square_size},#{4*plus_size - y*square_size - plus_size/2})"})) end # Add an extra one at top-right and bottom-right, for tiling. if (x == 0 && y == 0) svg.group(plus_shape, styles.merge({ "transform" => "translate(#{4*plus_size - x*square_size + dx*square_size - square_size},#{4*plus_size - y*square_size - plus_size/2})"})) end i += 1 end end end |