Class: Ass::Color
- Inherits:
-
Object
- Object
- Ass::Color
- Defined in:
- lib/mpv_ass/color.rb
Overview
Represents an ASS color.
Constant Summary collapse
- PRESETS =
{ # grayscale black: [ 0, 0, 0], carbon: [ 64, 64, 64], gray: [128, 128, 128], silver: [192, 192, 192], white: [255, 255, 255], # primary red: [255, 0, 0], green: [ 0, 255, 0], blue: [ 0, 0, 255], # secondary yellow: [255, 255, 0], magenta: [255, 0, 255], cyan: [ 0, 255, 255], # vivid orange: [255, 128, 0], gold: [255, 192, 0], purple: [128, 0, 255], turquoise: [ 0, 255, 128], # pastel pink: [255, 128, 255], sky: [128, 255, 255], mint: [128, 255, 128], vanilla: [255, 255, 128], coral: [255, 128, 128], # shade maroon: [128, 0, 0], forest: [ 0, 128, 0], navy: [ 0, 0, 128], teal: [ 0, 128, 128], plum: [128, 0, 128], olive: [128, 128, 0], brown: [128, 64, 0], }.freeze
Instance Attribute Summary collapse
-
#codes ⇒ Array<Integer>
(also: #to_a)
readonly
Gets the RGBA component values.
Instance Method Summary collapse
-
#alpha(code) ⇒ self
Changes the alpha value.
-
#blue(code) ⇒ self
Changes the blue value.
-
#green(code) ⇒ self
Changes the green value.
-
#initialize(color) ⇒ Color
constructor
Creates an ASS::Color.
-
#red(code) ⇒ self
Changes the red value.
-
#set(color) ⇒ self
Changes the color value.
-
#to_script ⇒ String
Converts the color to ASS syntax.
Constructor Details
#initialize(color) ⇒ Color
Creates an ASS::Color.
56 57 58 |
# File 'lib/mpv_ass/color.rb', line 56 def initialize(color) set(color) end |
Instance Attribute Details
#codes ⇒ Array<Integer> (readonly) Also known as: to_a
Gets the RGBA component values.
49 50 51 |
# File 'lib/mpv_ass/color.rb', line 49 def codes @codes end |
Instance Method Details
#alpha(code) ⇒ self
Changes the alpha value.
99 100 101 102 |
# File 'lib/mpv_ass/color.rb', line 99 def alpha(code) @codes[3] = code.to_i.clamp(0, 255) self end |
#blue(code) ⇒ self
Changes the blue value.
90 91 92 93 |
# File 'lib/mpv_ass/color.rb', line 90 def blue(code) @codes[2] = code.to_i.clamp(0, 255) self end |
#green(code) ⇒ self
Changes the green value.
82 83 84 85 |
# File 'lib/mpv_ass/color.rb', line 82 def green(code) @codes[1] = code.to_i.clamp(0, 255) self end |
#red(code) ⇒ self
Changes the red value.
74 75 76 77 |
# File 'lib/mpv_ass/color.rb', line 74 def red(code) @codes[0] = code.to_i.clamp(0, 255) self end |
#set(color) ⇒ self
Changes the color value.
65 66 67 68 69 |
# File 'lib/mpv_ass/color.rb', line 65 def set(color) color = PRESETS.fetch(color) if color.is_a?(Symbol) @codes = color.to_a.values_at(0..3).map{ |code| code.to_i.clamp(0, 255) } self end |
#to_script ⇒ String
Converts the color to ASS syntax.
106 107 108 109 |
# File 'lib/mpv_ass/color.rb', line 106 def to_script codes = @codes.last.zero? ? @codes[0..-2] : @codes "&H#{codes.reverse.map{ |code| "%02X" % code }.join}&" end |