Class: Rainbow::OpacityRange
- Inherits:
-
Object
- Object
- Rainbow::OpacityRange
- Defined in:
- lib/rainbow/opacity_range.rb
Instance Attribute Summary collapse
-
#first_width ⇒ Object
readonly
Returns the value of attribute first_width.
-
#from_location_in_pixel ⇒ Object
readonly
Returns the value of attribute from_location_in_pixel.
-
#from_opacity ⇒ Object
readonly
Returns the value of attribute from_opacity.
-
#gradient ⇒ Object
Returns the value of attribute gradient.
-
#leftover_width ⇒ Object
readonly
Returns the value of attribute leftover_width.
-
#mid_location_in_pixel ⇒ Object
readonly
Returns the value of attribute mid_location_in_pixel.
-
#mid_opacity ⇒ Object
readonly
Returns the value of attribute mid_opacity.
-
#mid_point ⇒ Object
readonly
Returns the value of attribute mid_point.
-
#scale_end_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_end_in_pixel.
-
#scale_mid_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_mid_in_pixel.
-
#scale_start_in_pixel ⇒ Object
readonly
Returns the value of attribute scale_start_in_pixel.
-
#second_width ⇒ Object
readonly
Returns the value of attribute second_width.
-
#tmp_current_x ⇒ Object
readonly
Returns the value of attribute tmp_current_x.
-
#tmp_diff ⇒ Object
readonly
Returns the value of attribute tmp_diff.
-
#tmp_distance_in_pixel ⇒ Object
readonly
Returns the value of attribute tmp_distance_in_pixel.
-
#tmp_from ⇒ Object
readonly
Returns the value of attribute tmp_from.
-
#tmp_to ⇒ Object
readonly
Returns the value of attribute tmp_to.
-
#to_location_in_pixel ⇒ Object
readonly
Returns the value of attribute to_location_in_pixel.
-
#to_opacity ⇒ Object
readonly
Returns the value of attribute to_opacity.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #current_x=(x) ⇒ Object
- #included?(x) ⇒ Boolean
-
#initialize(from_opacity, to_opacity, mid_point) ⇒ OpacityRange
constructor
A new instance of OpacityRange.
Constructor Details
#initialize(from_opacity, to_opacity, mid_point) ⇒ OpacityRange
Returns a new instance of OpacityRange.
9 10 11 12 13 14 15 |
# File 'lib/rainbow/opacity_range.rb', line 9 def initialize(from_opacity, to_opacity, mid_point) @from_opacity = from_opacity @to_opacity = to_opacity @mid_point = mid_point @mid_opacity = from_opacity.value + (to_opacity.value - from_opacity.value) / 2 end |
Instance Attribute Details
#first_width ⇒ Object (readonly)
Returns the value of attribute first_width.
4 5 6 |
# File 'lib/rainbow/opacity_range.rb', line 4 def first_width @first_width end |
#from_location_in_pixel ⇒ Object (readonly)
Returns the value of attribute from_location_in_pixel.
5 6 7 |
# File 'lib/rainbow/opacity_range.rb', line 5 def from_location_in_pixel @from_location_in_pixel end |
#from_opacity ⇒ Object (readonly)
Returns the value of attribute from_opacity.
3 4 5 |
# File 'lib/rainbow/opacity_range.rb', line 3 def from_opacity @from_opacity end |
#gradient ⇒ Object
Returns the value of attribute gradient.
3 4 5 |
# File 'lib/rainbow/opacity_range.rb', line 3 def gradient @gradient end |
#leftover_width ⇒ Object (readonly)
Returns the value of attribute leftover_width.
4 5 6 |
# File 'lib/rainbow/opacity_range.rb', line 4 def leftover_width @leftover_width end |
#mid_location_in_pixel ⇒ Object (readonly)
Returns the value of attribute mid_location_in_pixel.
5 6 7 |
# File 'lib/rainbow/opacity_range.rb', line 5 def mid_location_in_pixel @mid_location_in_pixel end |
#mid_opacity ⇒ Object (readonly)
Returns the value of attribute mid_opacity.
3 4 5 |
# File 'lib/rainbow/opacity_range.rb', line 3 def mid_opacity @mid_opacity end |
#mid_point ⇒ Object (readonly)
Returns the value of attribute mid_point.
3 4 5 |
# File 'lib/rainbow/opacity_range.rb', line 3 def mid_point @mid_point end |
#scale_end_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_end_in_pixel.
7 8 9 |
# File 'lib/rainbow/opacity_range.rb', line 7 def scale_end_in_pixel @scale_end_in_pixel end |
#scale_mid_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_mid_in_pixel.
7 8 9 |
# File 'lib/rainbow/opacity_range.rb', line 7 def scale_mid_in_pixel @scale_mid_in_pixel end |
#scale_start_in_pixel ⇒ Object (readonly)
Returns the value of attribute scale_start_in_pixel.
7 8 9 |
# File 'lib/rainbow/opacity_range.rb', line 7 def scale_start_in_pixel @scale_start_in_pixel end |
#second_width ⇒ Object (readonly)
Returns the value of attribute second_width.
4 5 6 |
# File 'lib/rainbow/opacity_range.rb', line 4 def second_width @second_width end |
#tmp_current_x ⇒ Object (readonly)
Returns the value of attribute tmp_current_x.
6 7 8 |
# File 'lib/rainbow/opacity_range.rb', line 6 def tmp_current_x @tmp_current_x end |
#tmp_diff ⇒ Object (readonly)
Returns the value of attribute tmp_diff.
6 7 8 |
# File 'lib/rainbow/opacity_range.rb', line 6 def tmp_diff @tmp_diff end |
#tmp_distance_in_pixel ⇒ Object (readonly)
Returns the value of attribute tmp_distance_in_pixel.
6 7 8 |
# File 'lib/rainbow/opacity_range.rb', line 6 def tmp_distance_in_pixel @tmp_distance_in_pixel end |
#tmp_from ⇒ Object (readonly)
Returns the value of attribute tmp_from.
6 7 8 |
# File 'lib/rainbow/opacity_range.rb', line 6 def tmp_from @tmp_from end |
#tmp_to ⇒ Object (readonly)
Returns the value of attribute tmp_to.
6 7 8 |
# File 'lib/rainbow/opacity_range.rb', line 6 def tmp_to @tmp_to end |
#to_location_in_pixel ⇒ Object (readonly)
Returns the value of attribute to_location_in_pixel.
5 6 7 |
# File 'lib/rainbow/opacity_range.rb', line 5 def to_location_in_pixel @to_location_in_pixel end |
#to_opacity ⇒ Object (readonly)
Returns the value of attribute to_opacity.
3 4 5 |
# File 'lib/rainbow/opacity_range.rb', line 3 def to_opacity @to_opacity end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/rainbow/opacity_range.rb', line 4 def width @width end |
Instance Method Details
#current_x=(x) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rainbow/opacity_range.rb', line 26 def current_x=(x) if x == 0 && from_opacity.location > 0 @tmp_current_x = 0.0 @tmp_diff = 0 @tmp_from = from_opacity.value @tmp_to = from_opacity.value @tmp_distance_in_pixel = from_location_in_pixel elsif x == to_location_in_pixel && to_opacity.location < 100 @tmp_current_x = 0.0 @tmp_diff = 0 @tmp_from = to_opacity.value @tmp_to = to_opacity.value @tmp_distance_in_pixel = leftover_width elsif x == from_location_in_pixel && gradient.scale_100? @tmp_current_x = 0.0 @tmp_diff = mid_opacity - from_opacity.value @tmp_from = from_opacity.value @tmp_to = mid_opacity @tmp_distance_in_pixel = first_width elsif x == mid_location_in_pixel && gradient.scale_100? @tmp_current_x = 0.0 @tmp_diff = to_opacity.value - mid_opacity @tmp_from = mid_opacity @tmp_to = to_opacity.value @tmp_distance_in_pixel = second_width elsif x == from_location_in_pixel && !gradient.scale_100? @tmp_current_x = 0.0 @tmp_diff = 0 @tmp_from = from_opacity.value @tmp_to = from_opacity.value @tmp_distance_in_pixel = 1 elsif x == gradient.scale_start_location_in_pixel && !gradient.scale_100? @tmp_current_x = 0.0 @tmp_diff = mid_opacity - from_opacity.value @tmp_from = from_opacity.value @tmp_to = from_opacity.value @tmp_distance_in_pixel = gradient.scale_half_distance_in_pixel elsif x == gradient.scale_mid_location_in_pixel && !gradient.scale_100? @tmp_current_x = 0.0 @tmp_diff = to_opacity.value - mid_opacity @tmp_from = mid_opacity @tmp_to = to_opacity.value @tmp_distance_in_pixel = gradient.scale_half_distance_in_pixel else @tmp_current_x += 1 end end |
#included?(x) ⇒ Boolean
17 18 19 |
# File 'lib/rainbow/opacity_range.rb', line 17 def included?(x) @from_location_in_pixel <= x && x <= @to_location_in_pixel end |