Class: DYI::Drawing::ColorEffect::RadialGradient

Inherits:
Object
  • Object
show all
Defined in:
lib/dyi/drawing/color_effect.rb

Overview

Class representing a radial gradient.

Since:

  • 1.3.0

Constant Summary collapse

SPREAD_METHODS =

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

Since:

  • 1.3.0

['pad', 'reflect', 'repeat']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(center_point, radius, focal_point = nil, spread_method = nil) ⇒ RadialGradient

Returns a new instance of RadialGradient.

Since:

  • 1.3.0



127
128
129
130
131
132
133
# File 'lib/dyi/drawing/color_effect.rb', line 127

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

Instance Attribute Details

#center_pointCoordinate (readonly)

Returns a center point of largest circle for the radial gradient.

Since:

  • 1.3.0



105
106
107
# File 'lib/dyi/drawing/color_effect.rb', line 105

def center_point
  @center_point
end

#focal_pointCoordinate (readonly)

Returns a focal point of largest circle for the radial gradient.

Since:

  • 1.3.0



110
111
112
# File 'lib/dyi/drawing/color_effect.rb', line 110

def focal_point
  @focal_point
end

#radiusLength (readonly)

Returns a radius of largest circle for the radial gradient.

Since:

  • 1.3.0



107
108
109
# File 'lib/dyi/drawing/color_effect.rb', line 107

def radius
  @radius
end

#spread_methodString

Returns a string that mean what happens if the gradient starts or ends inside the bounds of the objects being painted by the gradient.

Since:

  • 1.3.0



114
115
116
# File 'lib/dyi/drawing/color_effect.rb', line 114

def spread_method
  @spread_method
end

Class Method Details

.simple_gradation(*colors) ⇒ RadialGradient

Create a gradient on which spaced the specified colors.

Since:

  • 1.3.0



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/dyi/drawing/color_effect.rb', line 196

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

Instance Method Details

#add_color(offset, color) ⇒ Object

Adds a color to the gradient.

Since:

  • 1.3.0



139
140
141
# File 'lib/dyi/drawing/color_effect.rb', line 139

def add_color(offset, color)
  @child_elements.push(GradientStop.new(offset, :color => color))
end

#add_color_opacity(offset, color, opacity) ⇒ Object

Adds a color and a opacity to the gradient.

Since:

  • 1.3.0



156
157
158
# File 'lib/dyi/drawing/color_effect.rb', line 156

def add_color_opacity(offset, color, opacity)
  @child_elements.push(GradientStop.new(offset, :color => color, :opacity => opacity))
end

#add_opacity(offset, opacity) ⇒ Object

Adds a opacity to the gradient.

Since:

  • 1.3.0



147
148
149
# File 'lib/dyi/drawing/color_effect.rb', line 147

def add_opacity(offset, opacity)
  @child_elements.push(GradientStop.new(offset, :opacity => opacity))
end

#child_elementsArray<GradientStop>

Returns the array of the gradient colors.

Since:

  • 1.3.0



171
172
173
# File 'lib/dyi/drawing/color_effect.rb', line 171

def child_elements
  @child_elements.clone
end

#color?Boolean

Returns whether this object is a color.

Since:

  • 1.3.0



177
178
179
# File 'lib/dyi/drawing/color_effect.rb', line 177

def color?
  true
end

#write_as(formatter, io = $>) ⇒ Object

Writes the gradient on io object.

Since:

  • 1.3.0



185
186
187
# File 'lib/dyi/drawing/color_effect.rb', line 185

def write_as(formatter, io=$>)
  formatter.write_radial_gradient(self, io)
end