Class: Colors::LinearSegmentedColormap
- Defined in:
- lib/colors/linear_segmented_colormap.rb
Constant Summary
Constants inherited from Colormap
Colormap::PNG_HEIGHT, Colormap::PNG_WIDTH
Instance Attribute Summary collapse
-
#gamma ⇒ Object
Returns the value of attribute gamma.
-
#segmented_data ⇒ Object
readonly
Returns the value of attribute segmented_data.
Attributes inherited from Colormap
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, segmented_data, n_colors: 256, gamma: 1.0) ⇒ LinearSegmentedColormap
constructor
A new instance of LinearSegmentedColormap.
Methods inherited from Colormap
#[], #over_color, #over_color=, #reversed, #to_html, #to_png, #under_color, #under_color=
Constructor Details
#initialize(name, segmented_data, n_colors: 256, gamma: 1.0) ⇒ LinearSegmentedColormap
Returns a new instance of LinearSegmentedColormap.
3 4 5 6 7 8 9 |
# File 'lib/colors/linear_segmented_colormap.rb', line 3 def initialize(name, segmented_data, n_colors: 256, gamma: 1.0) super(name, n_colors) @monochrome = false @segmented_data = segmented_data @gamma = gamma end |
Instance Attribute Details
#gamma ⇒ Object
Returns the value of attribute gamma.
11 12 13 |
# File 'lib/colors/linear_segmented_colormap.rb', line 11 def gamma @gamma end |
#segmented_data ⇒ Object (readonly)
Returns the value of attribute segmented_data.
11 12 13 |
# File 'lib/colors/linear_segmented_colormap.rb', line 11 def segmented_data @segmented_data end |
Class Method Details
.new_from_list(name, colors, n_colors: 256, gamma: 1.0) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/colors/linear_segmented_colormap.rb', line 13 def self.new_from_list(name, colors, n_colors: 256, gamma: 1.0) case colors when Enumerable colors = colors.to_a else ary = Array.try_convert(colors) if ary.nil? raise ArgumentError, "colors must be convertible to an array: %p for %s" % [colors, name] else colors = ary end end case colors[0] when Array unless colors.all? {|a| a.length == 2 } raise ArgumentError, "colors array has invalid items" end vals, colors = colors.transpose else vals = Utils.linspace(0r, 1r, colors.length) end r, g, b, a = colors.map { |c| Utils.make_color(c).to_rgba.components }.transpose segmented_data = { red: [vals, r, r].transpose, green: [vals, g, g].transpose, blue: [vals, b, b].transpose, alpha: [vals, a, a].transpose } new(name, segmented_data, n_colors: n_colors, gamma: gamma) end |