Package stdlib

Class RGBColor

java.lang.Object
stdlib.RGBColor

public class RGBColor extends Object
This class provides a representation for a color in RGB space.
Author:
Swami Iyer
  • Constructor Summary

    Constructors
    Constructor
    Description
    RGBColor(int r, int g, int b)
    Constructs a color given its RGB components.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the blue component of this color.
    int
    Returns the green component of this color.
    int
    Returns the red component of this color.
    boolean
    Returns true if this color is compatible with other, and false otherwise.
    double
    Returns the luminance of this color.
    static void
    main(String[] args)
    Unit tests this data type.
    Returns the grayscale equivalent of this color.
    Returns a string representation of this color.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RGBColor

      public RGBColor(int r, int g, int b)
      Constructs a color given its RGB components.
      Parameters:
      r - red component
      g - green component
      b - blue component
  • Method Details

    • getRed

      public int getRed()
      Returns the red component of this color.
      Returns:
      the red component
    • getGreen

      public int getGreen()
      Returns the green component of this color.
      Returns:
      the green component
    • getBlue

      public int getBlue()
      Returns the blue component of this color.
      Returns:
      the blue component
    • luminance

      public double luminance()
      Returns the luminance of this color.
      Returns:
      the luminance
    • toGray

      public RGBColor toGray()
      Returns the grayscale equivalent of this color.
      Returns:
      the grayscale equivalent
    • isCompatible

      public boolean isCompatible(RGBColor other)
      Returns true if this color is compatible with other, and false otherwise.
      Parameters:
      other - the other color
      Returns:
      true if this color is compatible with other, and false otherwise
    • toString

      public String toString()
      Returns a string representation of this color.
      Overrides:
      toString in class Object
      Returns:
      a string representation
    • main

      public static void main(String[] args)
      Unit tests this data type.
      Parameters:
      args - command-line arguments