Class: Rszr::Color::Gradient

Inherits:
Object
  • Object
show all
Defined in:
lib/rszr/color/gradient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ Gradient

Returns a new instance of Gradient.

Yields:

  • (_self)

Yield Parameters:



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

#pointsObject (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

#to_fill(angle = 0) ⇒ Object



35
36
37
# File 'lib/rszr/color/gradient.rb', line 35

def to_fill(angle = 0)
  Fill.new(gradient: self, angle: angle)
end