class DYI::Drawing::ColorEffect::RadialGradient

Class representing a radial gradient. @since 1.3.0

Constants

SPREAD_METHODS

Array of strings that can be indicated as the property spread method.

Attributes

center_point[R]

@return [Coordinate] a center point of largest circle for the radial

gradient
focal_point[R]

@return [Coordinate] a focal point of largest circle for the radial

gradient
radius[R]

@return [Length] a radius of largest circle for the radial gradient

spread_method[R]

@return [String] a string that mean what happens if the gradient

starts or ends inside the bounds of the objects being painted by the
gradient

Public Class Methods

new(center_point, radius, focal_point=nil, spread_method=nil) click to toggle source

@param [Array<Numeric>] center_point a relative position of the center

point to the shape that is drawn

@param [Numeric] radius a relative length of largest circle for the

radial gradient to the shape that is drawn

@param [Array<Numeric>] focal_point a relative position of the focal

point of largest circle for the radial gradient to the shape that is
drawn. If this paramater is nil, this paramater is considered to
indicate the same value as center_point

@param [String] spread_method a string that mean what happens if the

gradient starts or ends inside the bounds of the objects being
painted by the gradient
# File lib/dyi/drawing/color_effect.rb, line 126
def initialize(center_point, radius, focal_point=nil, spread_method=nil)
  @center_point = Coordinate.new(center_point)
  @radius = Length.new(radius)
  @focal_point = focal_point ? Coordinate.new(focal_point) : @center_point
  self.spread_method = spread_method
  @child_elements = []
end
simple_gradation(*colors) click to toggle source

Create a gradient on which spaced the specified colors. @param [Color] colors a color that the gradient uses @return [RadialGradient] a gradient on which spaced the colors

# File lib/dyi/drawing/color_effect.rb, line 195
def simple_gradation(*colors)
  case count = colors.size
  when 0
    nil
  when 1
    Color.new(colors.first)
  else
    obj = new(['50%','50%'], '50%', ['50%','50%'])
    colors.each_with_index do |color, i|
      obj.add_color(i.quo(count - 1), color)
    end
    obj
  end
end

Public Instance Methods

add_color(offset, color) click to toggle source

Adds a color to the gradient. @param [Numeirc] offset a ratio of distance from focal point to the

edge of the largest circle

@param [Color] color a color at the offset point

# File lib/dyi/drawing/color_effect.rb, line 138
def add_color(offset, color)
  @child_elements.push(GradientStop.new(offset, :color => color))
end
add_color_opacity(offset, color, opacity) click to toggle source

Adds a color and a opacity to the gradient. @param [Numeirc] offset a ratio of distance from focal point to the

edge of the largest circle

@param [Color] color a color at the offset point @param [Numeric] opacity a opecity at the offset point

# File lib/dyi/drawing/color_effect.rb, line 155
def add_color_opacity(offset, color, opacity)
  @child_elements.push(GradientStop.new(offset, :color => color, :opacity => opacity))
end
add_opacity(offset, opacity) click to toggle source

Adds a opacity to the gradient. @param [Numeirc] offset a ratio of distance from focal point to the

edge of the largest circle

@param [Numeric] opacity a opecity at the offset point

# File lib/dyi/drawing/color_effect.rb, line 146
def add_opacity(offset, opacity)
  @child_elements.push(GradientStop.new(offset, :opacity => opacity))
end
child_elements() click to toggle source

Returns the array of the gradient colors. @return [Array<GradientStop>] the array of the gradient colors

# File lib/dyi/drawing/color_effect.rb, line 170
def child_elements
  @child_elements.clone
end
color?() click to toggle source

Returns whether this object is a color. @return [Boolean] always false

# File lib/dyi/drawing/color_effect.rb, line 176
def color?
  true
end
spread_method=(value) click to toggle source

Sets value to the spread method property. @param [String] spread_method a string that mean what happens if the

gradient starts or ends inside the bounds of the objects being
painted by the gradient
# File lib/dyi/drawing/color_effect.rb, line 163
def spread_method=(value)
  raise ArgumentError, "\"#{value}\" is invalid spreadMethod" if value && !SPREAD_METHODS.include?(value)
  @spread_method = value
end
write_as(formatter, io=$>) click to toggle source

Writes the gradient on io object. @param [Formatter::Base] formatter an object that defines the image

format

@param [IO] io an io to be written

# File lib/dyi/drawing/color_effect.rb, line 184
def write_as(formatter, io=$>)
  formatter.write_radial_gradient(self, io)
end