Method: Processing::GraphicsContext#colorMode

Defined in:
lib/processing/graphics_context.rb

#colorMode(mode) ⇒ RGB, HSB #colorMode(mode, max) ⇒ RGB, HSB #colorMode(mode, max1, max2, max3) ⇒ RGB, HSB #colorMode(mode, max1, max2, max3, maxA) ⇒ RGB, HSB

Sets color mode and max color values.

Parameters:

  • mode (RGB, HSB) (defaults to: nil)

    RGB or HSB

  • max (Numeric)

    max values for all color values

  • max1 (Numeric)

    max value for red or hue

  • max2 (Numeric)

    max value for green or saturation

  • max3 (Numeric)

    max value for blue or brightness

  • maxA (Numeric)

    max value for alpha

Returns:

See Also:



659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/processing/graphics_context.rb', line 659

def colorMode(mode = nil, *maxes)
  if mode != nil
    mode = mode.downcase.to_sym
    raise ArgumentError, "invalid color mode: #{mode}" unless [RGB, HSB].include?(mode)
    raise ArgumentError unless [0, 1, 3, 4].include?(maxes.size)

    @colorMode__ = mode
    @hsbColor__  = mode == HSB
    case maxes.size
    when 1    then @colorMaxes__                 = [maxes.first.to_f] * 4
    when 3, 4 then @colorMaxes__[0...maxes.size] = maxes.map &:to_f
    end
  end
  @colorMode__
end