Class: Rainbow::ColorRange

Inherits:
Object
  • Object
show all
Defined in:
lib/rainbow/color_range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_color, to_color, mid_point) ⇒ ColorRange

Returns a new instance of ColorRange.



12
13
14
15
16
17
18
# File 'lib/rainbow/color_range.rb', line 12

def initialize(from_color, to_color, mid_point)
  @from_color = from_color
  @to_color   = to_color
  @mid_point  = mid_point

  @current_x  = nil
end

Instance Attribute Details

#current_xObject

Returns the value of attribute current_x.



4
5
6
# File 'lib/rainbow/color_range.rb', line 4

def current_x
  @current_x
end

#first_widthObject (readonly)

Returns the value of attribute first_width.



4
5
6
# File 'lib/rainbow/color_range.rb', line 4

def first_width
  @first_width
end

#from_colorObject (readonly)

Returns the value of attribute from_color.



3
4
5
# File 'lib/rainbow/color_range.rb', line 3

def from_color
  @from_color
end

#from_location_in_pixelObject (readonly)

Returns the value of attribute from_location_in_pixel.



5
6
7
# File 'lib/rainbow/color_range.rb', line 5

def from_location_in_pixel
  @from_location_in_pixel
end

#gradientObject

Returns the value of attribute gradient.



3
4
5
# File 'lib/rainbow/color_range.rb', line 3

def gradient
  @gradient
end

#leftover_widthObject (readonly)

Returns the value of attribute leftover_width.



5
6
7
# File 'lib/rainbow/color_range.rb', line 5

def leftover_width
  @leftover_width
end

#mid_colorObject (readonly)

Returns the value of attribute mid_color.



3
4
5
# File 'lib/rainbow/color_range.rb', line 3

def mid_color
  @mid_color
end

#mid_location_in_pixelObject (readonly)

Returns the value of attribute mid_location_in_pixel.



5
6
7
# File 'lib/rainbow/color_range.rb', line 5

def mid_location_in_pixel
  @mid_location_in_pixel
end

#mid_pointObject (readonly)

Returns the value of attribute mid_point.



3
4
5
# File 'lib/rainbow/color_range.rb', line 3

def mid_point
  @mid_point
end

#opacity_rangesObject

Returns the value of attribute opacity_ranges.



10
11
12
# File 'lib/rainbow/color_range.rb', line 10

def opacity_ranges
  @opacity_ranges
end

#second_widthObject (readonly)

Returns the value of attribute second_width.



4
5
6
# File 'lib/rainbow/color_range.rb', line 4

def second_width
  @second_width
end

#tmp_current_xObject (readonly)

Returns the value of attribute tmp_current_x.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_current_x
  @tmp_current_x
end

#tmp_diff_bObject (readonly)

Returns the value of attribute tmp_diff_b.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_diff_b
  @tmp_diff_b
end

#tmp_diff_gObject (readonly)

Returns the value of attribute tmp_diff_g.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_diff_g
  @tmp_diff_g
end

#tmp_diff_rObject (readonly)

Returns the value of attribute tmp_diff_r.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_diff_r
  @tmp_diff_r
end

#tmp_distance_in_pixelObject (readonly)

Returns the value of attribute tmp_distance_in_pixel.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_distance_in_pixel
  @tmp_distance_in_pixel
end

#tmp_from_colorObject (readonly)

Returns the value of attribute tmp_from_color.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_from_color
  @tmp_from_color
end

#tmp_to_colorObject (readonly)

Returns the value of attribute tmp_to_color.



7
8
9
# File 'lib/rainbow/color_range.rb', line 7

def tmp_to_color
  @tmp_to_color
end

#to_colorObject (readonly)

Returns the value of attribute to_color.



3
4
5
# File 'lib/rainbow/color_range.rb', line 3

def to_color
  @to_color
end

#to_location_in_pixelObject (readonly)

Returns the value of attribute to_location_in_pixel.



5
6
7
# File 'lib/rainbow/color_range.rb', line 5

def to_location_in_pixel
  @to_location_in_pixel
end

#widthObject (readonly)

Returns the value of attribute width.



4
5
6
# File 'lib/rainbow/color_range.rb', line 4

def width
  @width
end

Instance Method Details

#current_colorObject



33
34
35
36
37
38
39
40
41
# File 'lib/rainbow/color_range.rb', line 33

def current_color
  if less_than_scale_range?
    ChunkyPNG::Color(from_color.r, from_color.g, from_color.b, @tmp_opacity)
  elsif greater_than_scale_range?
    ChunkyPNG::Color(to_color.r, to_color.g, to_color.b, @tmp_opacity)
  else
    ChunkyPNG::Color(color(:r), color(:g), color(:b), @tmp_opacity)
  end
end