Module: Sai::Decorator::Gradients Abstract Private

Included in:
Sai::Decorator
Defined in:
lib/sai/decorator/gradients.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.

This module is abstract.

This module is meant to be included in the Sai::Decorator class to provide color gradient methods

Color gradient methods for the Sai::Decorator class

Author:

Since:

  • 0.3.1

Instance Method Summary collapse

Instance Method Details

#gradient(start_color, end_color, steps) ⇒ Decorator

Build a foreground gradient between two colors for text decoration

Examples:

Create a foreground gradient from red to blue

decorator.gradient(:red, :blue, 10).decorate('Hello, World!')
#=> "\e[38;2;255;0;0mH\e[0m\e[38;2;204;0;51me\e[0m..."

Parameters:

  • start_color (Array<Integer>, String, Symbol) —

    the starting color

  • end_color (Array<Integer>, String, Symbol) —

    the ending color

  • steps (Integer) —

    the number of gradient steps (minimum 2)

Returns:

  • (Decorator) —

    a new instance of Decorator with foreground gradient colors

Raises:

  • (ArgumentError) —

    if steps is less than 2

Author:

Since:

  • 0.3.1



38
39
40
41
# File 'lib/sai/decorator/gradients.rb', line 38

def gradient(start_color, end_color, steps)
  colors = Conversion::RGB.transform.gradient(start_color, end_color, steps)
  dup.tap { |duped| duped.instance_variable_set(:@foreground_sequence, colors) } #: Decorator
end

#on_gradient(start_color, end_color, steps) ⇒ Decorator

Build a background gradient between two colors for text decoration

Examples:

Create a background gradient from red to blue

decorator.on_gradient(:red, :blue, 10).decorate('Hello, World!')
#=> "\e[48;2;255;0;0mH\e[0m\e[48;2;204;0;51me\e[0m..."

Parameters:

  • start_color (Array<Integer>, String, Symbol) —

    the starting color

  • end_color (Array<Integer>, String, Symbol) —

    the ending color

  • steps (Integer) —

    the number of gradient steps (minimum 2)

Returns:

  • (Decorator) —

    a new instance of Decorator with background gradient colors

Raises:

  • (ArgumentError) —

    if steps is less than 2

Author:

Since:

  • 0.3.1



65
66
67
68
# File 'lib/sai/decorator/gradients.rb', line 65

def on_gradient(start_color, end_color, steps)
  colors = Conversion::RGB.transform.gradient(start_color, end_color, steps)
  dup.tap { |duped| duped.instance_variable_set(:@background_sequence, colors) } #: Decorator
end

#on_rainbow(steps) ⇒ Decorator

Build a background rainbow gradient for text decoration

Examples:

Create a rainbow background gradient

decorator.on_rainbow(6).decorate('Hello, World!')
#=> "\e[48;2;255;0;0mH\e[0m\e[48;2;255;255;0me\e[0m..."

Parameters:

  • steps (Integer) —

    the number of colors to generate (minimum 2)

Returns:

  • (Decorator) —

    a new instance of Decorator with background rainbow colors

Raises:

  • (ArgumentError) —

    if steps is less than 2

Author:

Since:

  • 0.3.1



86
87
88
89
# File 'lib/sai/decorator/gradients.rb', line 86

def on_rainbow(steps)
  colors = Conversion::RGB.transform.rainbow_gradient(steps)
  dup.tap { |duped| duped.instance_variable_set(:@background_sequence, colors) } #: Decorator
end

#rainbow(steps) ⇒ Decorator

Build a foreground rainbow gradient for text decoration

Examples:

Create a rainbow text gradient

decorator.rainbow(6).decorate('Hello, World!')
#=> "\e[38;2;255;0;0mH\e[0m\e[38;2;255;255;0me\e[0m..."

Parameters:

  • steps (Integer) —

    the number of colors to generate (minimum 2)

Returns:

  • (Decorator) —

    a new instance of Decorator with foreground rainbow colors

Raises:

  • (ArgumentError) —

    if steps is less than 2

Author:

Since:

  • 0.3.1



107
108
109
110
# File 'lib/sai/decorator/gradients.rb', line 107

def rainbow(steps)
  colors = Conversion::RGB.transform.rainbow_gradient(steps)
  dup.tap { |duped| duped.instance_variable_set(:@foreground_sequence, colors) } #: Decorator
end