Class: DYI::Drawing::ColorEffect::RadialGradient
- Inherits:
-
Object
- Object
- DYI::Drawing::ColorEffect::RadialGradient
- Defined in:
- lib/dyi/drawing/color_effect.rb
Overview
Class representing a radial gradient.
Constant Summary collapse
- SPREAD_METHODS =
Array of strings that can be indicated as the property spread method.
['pad', 'reflect', 'repeat']
Instance Attribute Summary collapse
-
#center_point ⇒ Coordinate
readonly
A center point of largest circle for the radial gradient.
-
#focal_point ⇒ Coordinate
readonly
A focal point of largest circle for the radial gradient.
-
#radius ⇒ Length
readonly
A radius of largest circle for the radial gradient.
-
#spread_method ⇒ String
A string that mean what happens if the gradient starts or ends inside the bounds of the objects being painted by the gradient.
Class Method Summary collapse
-
.simple_gradation(*colors) ⇒ RadialGradient
Create a gradient on which spaced the specified colors.
Instance Method Summary collapse
-
#add_color(offset, color) ⇒ Object
Adds a color to the gradient.
-
#add_color_opacity(offset, color, opacity) ⇒ Object
Adds a color and a opacity to the gradient.
-
#add_opacity(offset, opacity) ⇒ Object
Adds a opacity to the gradient.
-
#child_elements ⇒ Array<GradientStop>
Returns the array of the gradient colors.
-
#color? ⇒ Boolean
Returns whether this object is a color.
-
#initialize(center_point, radius, focal_point = nil, spread_method = nil) ⇒ RadialGradient
constructor
A new instance of RadialGradient.
-
#write_as(formatter, io = $>) ⇒ Object
Writes the gradient on io object.
Constructor Details
#initialize(center_point, radius, focal_point = nil, spread_method = nil) ⇒ RadialGradient
Returns a new instance of RadialGradient.
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_point ⇒ Coordinate (readonly)
Returns a center point of largest circle for the radial gradient.
105 106 107 |
# File 'lib/dyi/drawing/color_effect.rb', line 105 def center_point @center_point end |
#focal_point ⇒ Coordinate (readonly)
Returns a focal point of largest circle for the radial gradient.
110 111 112 |
# File 'lib/dyi/drawing/color_effect.rb', line 110 def focal_point @focal_point end |
#radius ⇒ Length (readonly)
Returns a radius of largest circle for the radial gradient.
107 108 109 |
# File 'lib/dyi/drawing/color_effect.rb', line 107 def radius @radius end |
#spread_method ⇒ String
Returns a string that mean what happens if the gradient starts or ends inside the bounds of the objects being painted by the gradient.
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.
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.
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.
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.
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_elements ⇒ Array<GradientStop>
Returns the array of the gradient colors.
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.
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.
185 186 187 |
# File 'lib/dyi/drawing/color_effect.rb', line 185 def write_as(formatter, io=$>) formatter.write_radial_gradient(self, io) end |