Class: GeoPattern::ChevronPattern
- Inherits:
-
BasePattern
- Object
- Struct
- BasePattern
- GeoPattern::ChevronPattern
- Defined in:
- lib/geo_pattern/pattern/chevron_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
#build_chevron_shape(width, height) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/geo_pattern/pattern/chevron_pattern.rb', line 37 def build_chevron_shape(width, height) e = height * 0.66 [ %Q{polyline("0,0,#{width/2},#{height-e},#{width/2},#{height},0,#{e},0,0")}, %Q{polyline("#{width/2},#{height-e},#{width},0,#{width},#{e},#{width/2},#{height},#{width/2},#{height-e}")} ] end |
#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 |
# File 'lib/geo_pattern/pattern/chevron_pattern.rb', line 3 def render_to_svg chevron_width = map(hex_val(0, 1), 0, 15, 30, 80) chevron_height = map(hex_val(0, 1), 0, 15, 30, 80) chevron = build_chevron_shape(chevron_width, chevron_height) svg.set_width(chevron_width * 6) svg.set_height(chevron_height * 6 * 0.66) 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 = { "stroke" => STROKE_COLOR, "stroke-opacity" => STROKE_OPACITY, "fill" => fill, "fill-opacity" => opacity, "stroke-width" => 1 } svg.group(chevron, styles.merge({"transform" => "translate(#{x*chevron_width},#{y*chevron_height*0.66 - chevron_height/2})"})) # Add an extra row at the end that matches the first row, for tiling. if (y == 0) svg.group(chevron, styles.merge({"transform" => "translate(#{x*chevron_width},#{6*chevron_height*0.66 - chevron_height/2})"})) end i += 1 end end end |