Class: Rszr::Color::Gradient
- Inherits:
-
Object
- Object
- Rszr::Color::Gradient
- Defined in:
- lib/rszr/color/gradient.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
- #<<(position, red = nil, green = nil, blue = nil, alpha = 255) ⇒ Object (also: #point)
-
#initialize(*args) {|_self| ... } ⇒ Gradient
constructor
A new instance of Gradient.
-
#initialize_dup(other) ⇒ Object
:nodoc:.
- #to_fill(angle = 0) ⇒ Object
Constructor Details
#initialize(*args) {|_self| ... } ⇒ Gradient
Returns a new instance of Gradient.
7 8 9 10 11 12 13 |
# File 'lib/rszr/color/gradient.rb', line 7 def initialize(*args) @points = [] points = args.last.is_a?(Hash) ? args.pop.dup : {} args.each { |point| self << point } points.each { |pos, color| point(pos, color) } yield self if block_given? end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
5 6 7 |
# File 'lib/rszr/color/gradient.rb', line 5 def points @points end |
Instance Method Details
#<<(position, red = nil, green = nil, blue = nil, alpha = 255) ⇒ Object Also known as: point
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rszr/color/gradient.rb', line 19 def <<(position, red = nil, green = nil, blue= nil, alpha = 255) point = if red.is_a?(Point) red elsif red.is_a?(Color::Base) Point.new(position, red) elsif red.is_a?(String) && red.start_with?('#') Point.new(position, Color.hex(red)) else Point.new(position, RGBA.new(red, green, blue, alpha)) end points << point points.sort! end |
#initialize_dup(other) ⇒ Object
:nodoc:
15 16 17 |
# File 'lib/rszr/color/gradient.rb', line 15 def initialize_dup(other) # :nodoc: @points = other.points.map(&:dup) end |