Module: OutroRails::CircleOfFifthsHelper
- Defined in:
- app/helpers/outro_rails/circle_of_fifths_helper.rb
Constant Summary collapse
- WEDGE_DEGREES =
360.0 / 12
- WEDGE_GAP_DEGREES =
1.0
Instance Method Summary collapse
- #circle_point(cx, cy, radius, degrees) ⇒ Object
- #key_signature_label(key) ⇒ Object
- #wedge_label_point(cx, cy, inner_radius, outer_radius, index) ⇒ Object
- #wedge_path(cx, cy, inner_radius, outer_radius, index) ⇒ Object
Instance Method Details
#circle_point(cx, cy, radius, degrees) ⇒ Object
8 9 10 11 12 13 |
# File 'app/helpers/outro_rails/circle_of_fifths_helper.rb', line 8 def circle_point(cx, cy, radius, degrees) radians = (degrees - 90) * Math::PI / 180 [ (cx + radius * Math.cos(radians)).round(2), (cy + radius * Math.sin(radians)).round(2) ] end |
#key_signature_label(key) ⇒ Object
37 38 39 40 41 42 |
# File 'app/helpers/outro_rails/circle_of_fifths_helper.rb', line 37 def key_signature_label(key) count = key.signature return "no sharps or flats" if count.zero? pluralize(count.abs, count.positive? ? "sharp" : "flat") end |
#wedge_label_point(cx, cy, inner_radius, outer_radius, index) ⇒ Object
30 31 32 33 34 35 |
# File 'app/helpers/outro_rails/circle_of_fifths_helper.rb', line 30 def wedge_label_point(cx, cy, inner_radius, outer_radius, index) circle_point(cx, cy, (inner_radius + outer_radius) / 2.0, index * WEDGE_DEGREES) end |
#wedge_path(cx, cy, inner_radius, outer_radius, index) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/outro_rails/circle_of_fifths_helper.rb', line 15 def wedge_path(cx, cy, inner_radius, outer_radius, index) from = (index * WEDGE_DEGREES) - (WEDGE_DEGREES / 2) + WEDGE_GAP_DEGREES to = (index * WEDGE_DEGREES) + (WEDGE_DEGREES / 2) - WEDGE_GAP_DEGREES o1 = circle_point(cx, cy, outer_radius, from) o2 = circle_point(cx, cy, outer_radius, to) i2 = circle_point(cx, cy, inner_radius, to) i1 = circle_point(cx, cy, inner_radius, from) "M #{o1[0]} #{o1[1]} " \ "A #{outer_radius} #{outer_radius} 0 0 1 #{o2[0]} #{o2[1]} " \ "L #{i2[0]} #{i2[1]} " \ "A #{inner_radius} #{inner_radius} 0 0 0 #{i1[0]} #{i1[1]} Z" end |