Class: GeoPattern::OctagonPattern
- Inherits:
-
BasePattern
- Object
- Struct
- BasePattern
- GeoPattern::OctagonPattern
- Defined in:
- lib/geo_pattern/pattern/octagon_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_octogon_shape(square_size) ⇒ Object
29 30 31 32 33 |
# File 'lib/geo_pattern/pattern/octagon_pattern.rb', line 29 def build_octogon_shape(square_size) s = square_size c = s * 0.33 "#{c},0,#{s-c},0,#{s},#{c},#{s},#{s-c},#{s-c},#{s},#{c},#{s},0,#{s-c},0,#{c},#{c},0" 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 |
# File 'lib/geo_pattern/pattern/octagon_pattern.rb', line 3 def render_to_svg square_size = map(hex_val(0, 1), 0, 15, 10, 60) tile = build_octogon_shape(square_size) svg.set_width(square_size * 6) svg.set_height(square_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) svg.polyline(tile, { "fill" => fill, "fill-opacity" => opacity, "stroke" => STROKE_COLOR, "stroke-opacity" => STROKE_OPACITY, "transform" => "translate(#{x*square_size}, #{y*square_size})" }) i += 1 end end end |