Class: GeoPattern::SineWavePattern
- Inherits:
-
BasePattern
- Object
- Struct
- BasePattern
- GeoPattern::SineWavePattern
- Defined in:
- lib/geo_pattern/pattern/sine_wave_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 |
# File 'lib/geo_pattern/pattern/sine_wave_pattern.rb', line 3 def render_to_svg period = map(hex_val(0, 1), 0, 15, 100, 400).floor amplitude = map(hex_val(1, 1), 0, 15, 30, 100).floor wave_width = map(hex_val(2, 1), 0, 15, 3, 30).floor svg.set_width(period) svg.set_height(wave_width * 36) for i in 0..35 val = hex_val(i, 1) opacity = opacity(val) fill = fill_color(val) x_offset = period / 4 * 0.7 styles = { "fill" => "none", "stroke" => fill, "style" => { "opacity" => opacity, "stroke-width" => "#{wave_width}px" } } str = "M0 "+amplitude.to_s+ " C "+x_offset.to_s+" 0, "+(period/2 - x_offset).to_s+" 0, "+(period/2).to_s+" "+amplitude.to_s+ " S "+(period-x_offset).to_s+" "+(amplitude*2).to_s+", "+period.to_s+" "+amplitude.to_s+ " S "+(period*1.5-x_offset).to_s+" 0, "+(period*1.5).to_s+", "+amplitude.to_s; svg.path(str, styles.merge({"transform" => "translate(-#{period/4}, #{wave_width*i-amplitude*1.5})"})) svg.path(str, styles.merge({"transform" => "translate(-#{period/4}, #{wave_width*i-amplitude*1.5 + wave_width*36})"})) end end |