Module: Sai::Conversion::RGB::ColorTransformer Private
- Defined in:
- lib/sai/conversion/rgb/color_transformer.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Perform color transformations
Class Method Summary collapse
-
.darken(color, amount) ⇒ Array<Integer>
private
Darken an RGB color by a percentage.
-
.gradient(start_color, end_color, steps) ⇒ Array<Array<Integer>>
private
Generate a gradient between two colors with a specified number of steps.
-
.interpolate_color(start_color, end_color, step) ⇒ Array<Integer>
private
Interpolate between two colors to create a gradient step.
-
.lighten(color, amount) ⇒ Array<Integer>
private
Lighten an RGB color by a percentage.
-
.rainbow_gradient(steps) ⇒ Array<Array<Integer>>
private
Generate a rainbow gradient with a specified number of steps.
Class Method Details
.darken(color, amount) ⇒ Array<Integer>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Darken an RGB color by a percentage
29 30 31 32 33 34 |
# File 'lib/sai/conversion/rgb/color_transformer.rb', line 29 def darken(color, amount) raise ArgumentError, "Invalid amount: #{amount}" unless amount.between?(0.0, 1.0) rgb = ColorSpace.resolve(color) rgb.map { |c| [0, (c * (1 - amount)).round].max } end |
.gradient(start_color, end_color, steps) ⇒ Array<Array<Integer>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a gradient between two colors with a specified number of steps
54 55 56 57 58 59 60 61 |
# File 'lib/sai/conversion/rgb/color_transformer.rb', line 54 def gradient(start_color, end_color, steps) raise ArgumentError, "Steps must be at least 2, got: #{steps}" if steps < 2 (0...steps).map do |i| step = i.to_f / (steps - 1) interpolate_color(start_color, end_color, step) end end |
.interpolate_color(start_color, end_color, step) ⇒ Array<Integer>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Interpolate between two colors to create a gradient step
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sai/conversion/rgb/color_transformer.rb', line 81 def interpolate_color(start_color, end_color, step) raise ArgumentError, "Invalid step: #{step}" unless step.between?(0.0, 1.0) start_rgb = ColorSpace.resolve(start_color) end_rgb = ColorSpace.resolve(end_color) start_rgb.zip(end_rgb).map do |values| start_val, end_val = values next 0 unless start_val && end_val # Handle potential nil values (start_val + ((end_val - start_val) * step)).round.clamp(0, 255) end end |
.lighten(color, amount) ⇒ Array<Integer>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lighten an RGB color by a percentage
108 109 110 111 112 113 |
# File 'lib/sai/conversion/rgb/color_transformer.rb', line 108 def lighten(color, amount) raise ArgumentError, "Invalid amount: #{amount}" unless amount.between?(0.0, 1.0) rgb = ColorSpace.resolve(color) rgb.map { |c| [255, (c * (1 + amount)).round].min } end |
.rainbow_gradient(steps) ⇒ Array<Array<Integer>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a rainbow gradient with a specified number of steps
127 128 129 130 131 132 133 134 135 |
# File 'lib/sai/conversion/rgb/color_transformer.rb', line 127 def rainbow_gradient(steps) raise ArgumentError, "Steps must be at least 2, got: #{steps}" if steps < 2 hue_step = 360.0 / steps (0...steps).map do |i| hue = (i * hue_step) % 360 ColorSpace.hsv_to_rgb(hue, 1.0, 1.0) end end |