Class: Unmagic::Color::Gradient::Stop

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/color/gradient/stop.rb

Overview

A color stop at a specific position in a gradient.

Represents a single color at a position along a gradient. Positions are normalized from 0.0 (start) to 1.0 (end). Multiple stops define the color transitions in a gradient.

Usage

Stop objects are typically created automatically by gradient classes using the .build() method, but can be created directly for more control.

Examples

# Create a stop directly
stop = Unmagic::Color::Gradient::Stop.new(
color: Unmagic::Color::RGB.parse("#FF0000"),
position: 0.5
)

# Access stop properties
stop.color      # => #<RGB...>
stop.position   # => 0.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color:, position:) ⇒ Stop

Create a new color stop.

Parameters:

  • color (Color) —

    The color at this stop (must be a Color instance)

  • position (Numeric) —

    Position along gradient (0.0-1.0)

Raises:

  • (ArgumentError) —

    If color is not a Color instance

  • (ArgumentError) —

    If position is not between 0.0 and 1.0



38
39
40
41
42
43
44
# File 'lib/unmagic/color/gradient/stop.rb', line 38

def initialize(color:, position:)
  raise ArgumentError, "color must be a Color instance" unless color.is_a?(Unmagic::Color)
  raise ArgumentError, "position must be between 0.0 and 1.0" if position < 0.0 || position > 1.0

  @color = color
  @position = position.to_f
end

Instance Attribute Details

#color ⇒ Object (readonly)

Returns the value of attribute color.



29
30
31
# File 'lib/unmagic/color/gradient/stop.rb', line 29

def color
  @color
end

#position ⇒ Object (readonly)

Returns the value of attribute position.



29
30
31
# File 'lib/unmagic/color/gradient/stop.rb', line 29

def position
  @position
end