Class: Rainbow::Gradient
- Inherits:
-
Object
- Object
- Rainbow::Gradient
- Defined in:
- lib/rainbow/gradient.rb
Constant Summary collapse
- SUPPORTED_ANGLES =
[0, 180]
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#color_ranges ⇒ Object
readonly
Returns the value of attribute color_ranges.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#opacity_ranges ⇒ Object
readonly
Returns the value of attribute opacity_ranges.
-
#scale_end_location_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_end_location_in_pixel.
-
#scale_half_distance_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_half_distance_in_pixel.
-
#scale_mid_location_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_mid_location_in_pixel.
-
#scale_start_location_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_start_location_in_pixel.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #align_with_layer ⇒ Object
- #angle ⇒ Object
- #blend_mode ⇒ Object
- #create_canvas ⇒ Object
- #dither ⇒ Object
-
#initialize(width, height, args) ⇒ Gradient
constructor
wdith - The gradient width height - The gradient height args - Hash that describes the property of the gradient { blend_mode: ‘norm|diss|dark|…’, dither: true|false, opacity: 0..100, gradient: { type: ‘solid|noise’, smoothness: 0..100, color_ranges: [], opacity_ranges: [] }, reverse: true|false, style: ‘linear|radial|angle|reflected|diamond’, align_with_layer: true|false, angle: 0..360, scale: 10..150 }.
- #opacity ⇒ Object
- #reverse ⇒ Object
- #save_as_png(path) ⇒ Object
- #scale ⇒ Object
- #scale_100? ⇒ Boolean
- #smoothness ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(width, height, args) ⇒ Gradient
wdith - The gradient width height - The gradient height args - Hash that describes the property of the gradient
{
blend_mode: 'norm|diss|dark|...',
dither: true|false,
opacity: 0..100,
gradient: {
type: 'solid|noise',
smoothness: 0..100,
color_ranges: [],
opacity_ranges: []
},
reverse: true|false,
style: 'linear|radial|angle|reflected|diamond',
align_with_layer: true|false,
angle: 0..360,
scale: 10..150
}
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rainbow/gradient.rb', line 30 def initialize(width, height, args) @width = width @height = height @args = args @style = args[:style] @color_ranges = args[:gradient][:color_ranges] @opacity_ranges = OpacityRanges.new(args[:gradient][:opacity_ranges], self) assert_arguments! compute_scale_variables! end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
4 5 6 |
# File 'lib/rainbow/gradient.rb', line 4 def args @args end |
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
5 6 7 |
# File 'lib/rainbow/gradient.rb', line 5 def canvas @canvas end |
#color_ranges ⇒ Object (readonly)
Returns the value of attribute color_ranges.
4 5 6 |
# File 'lib/rainbow/gradient.rb', line 4 def color_ranges @color_ranges end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/rainbow/gradient.rb', line 4 def height @height end |
#opacity_ranges ⇒ Object (readonly)
Returns the value of attribute opacity_ranges.
4 5 6 |
# File 'lib/rainbow/gradient.rb', line 4 def opacity_ranges @opacity_ranges end |
#scale_end_location_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_end_location_in_pixel.
6 7 8 |
# File 'lib/rainbow/gradient.rb', line 6 def scale_end_location_in_pixel @scale_end_location_in_pixel end |
#scale_half_distance_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_half_distance_in_pixel.
6 7 8 |
# File 'lib/rainbow/gradient.rb', line 6 def scale_half_distance_in_pixel @scale_half_distance_in_pixel end |
#scale_mid_location_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_mid_location_in_pixel.
6 7 8 |
# File 'lib/rainbow/gradient.rb', line 6 def scale_mid_location_in_pixel @scale_mid_location_in_pixel end |
#scale_start_location_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_start_location_in_pixel.
6 7 8 |
# File 'lib/rainbow/gradient.rb', line 6 def scale_start_location_in_pixel @scale_start_location_in_pixel end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
4 5 6 |
# File 'lib/rainbow/gradient.rb', line 4 def style @style end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/rainbow/gradient.rb', line 4 def width @width end |
Instance Method Details
#align_with_layer ⇒ Object
77 78 79 |
# File 'lib/rainbow/gradient.rb', line 77 def align_with_layer args.fetch(:align_with_layer, true) end |
#angle ⇒ Object
81 82 83 84 |
# File 'lib/rainbow/gradient.rb', line 81 def angle value = args.fetch(:angle, 0) value % 360 end |
#blend_mode ⇒ Object
53 54 55 |
# File 'lib/rainbow/gradient.rb', line 53 def blend_mode args.fetch(:blend_mode, 'norm') end |
#create_canvas ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/rainbow/gradient.rb', line 43 def create_canvas @canvas = ChunkyPNG::Canvas.new(width, height, ChunkyPNG::Color::TRANSPARENT) paint_canvas!(@canvas) set_opacity!(@canvas) if opacity != 100 reverse!(@canvas) if reverse || angle == 180 @canvas end |
#dither ⇒ Object
57 58 59 |
# File 'lib/rainbow/gradient.rb', line 57 def dither args.fetch(:dither, false) end |
#opacity ⇒ Object
61 62 63 |
# File 'lib/rainbow/gradient.rb', line 61 def opacity args.fetch(:opacity, 100) end |
#reverse ⇒ Object
73 74 75 |
# File 'lib/rainbow/gradient.rb', line 73 def reverse args.fetch(:reverse, false) end |
#save_as_png(path) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/rainbow/gradient.rb', line 94 def save_as_png(path) create_canvas unless canvas canvas.save(path, :fast_rgba) path end |
#scale ⇒ Object
86 87 88 |
# File 'lib/rainbow/gradient.rb', line 86 def scale args.fetch(:scale, 100) end |
#scale_100? ⇒ Boolean
90 91 92 |
# File 'lib/rainbow/gradient.rb', line 90 def scale_100? scale == 100 end |
#smoothness ⇒ Object
69 70 71 |
# File 'lib/rainbow/gradient.rb', line 69 def smoothness args[:gradient][:smoothness] end |
#type ⇒ Object
65 66 67 |
# File 'lib/rainbow/gradient.rb', line 65 def type args[:gradient][:type] end |