Package primitives

Class Colour

java.lang.Object
primitives.Colour

public class Colour
extends java.lang.Object
This class represents a digital colour, with the added functionality of adding and scaling colours.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static Colour BLACK
    Black.
  • Constructor Summary

    Constructors
    Constructor Description
    Colour​(double red, double green, double blue)
    Construct a new colour from the given red, green, and blue values.
  • Method Summary

    Modifier and Type Method Description
    Colour add​(Colour colour)
    Add two colours together and return a new colour.
    static Colour average​(Colour... colours)
    Calculate the average between any number of colours.
    int blue()
    Get the integer value of blue of this colour.
    int green()
    Get the integer value of green of this colour.
    int red()
    Get the integer value of red of this colour.
    int rgb()
    Returns the RGB value representing the colour.
    Colour scale​(double factor)
    Scale this colour and return a new colour.
    Colour scale​(Factors factors)
    Scale this colour by three factors, one for each channel, and return a new colour.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BLACK

      public static final Colour BLACK
      Black.
  • Constructor Details

    • Colour

      public Colour​(double red, double green, double blue)
      Construct a new colour from the given red, green, and blue values. Negative values will be treated as 0 and values over 255 will be treated as 255.
      Parameters:
      red - The red value (0 to 255).
      green - The green value (0 to 255).
      blue - The blue value (0 to 255).
  • Method Details

    • add

      public Colour add​(Colour colour)
      Add two colours together and return a new colour. Adding two colours means adding their red values as the new red value, etc.
      Parameters:
      colour - The colour to add with this colour.
      Returns:
      The new colour which is the sum of the two colours.
    • scale

      public Colour scale​(double factor)
      Scale this colour and return a new colour. To scale a colour means to multiply the red, green, and blue values by some scale factor.
      Parameters:
      factor - The factor to scale this colour by.
      Returns:
      The new colour which is the result of the scale.
    • scale

      public Colour scale​(Factors factors)
      Scale this colour by three factors, one for each channel, and return a new colour. To scale a colour means to multiply the red, green, and blue values by some scale factor for each channel.
      Parameters:
      factors - The three factors to scale a channel of this colour by.
      Returns:
      The new colour which is the result of the scale.
    • red

      public int red()
      Get the integer value of red of this colour.
      Returns:
      The integer value (0-255) of red.
    • green

      public int green()
      Get the integer value of green of this colour.
      Returns:
      The integer value (0-255) of green.
    • blue

      public int blue()
      Get the integer value of blue of this colour.
      Returns:
      The integer value (0-255) of blue.
    • rgb

      public int rgb()
      Returns the RGB value representing the colour. (Bits 24-31 255 i.e. fully opaque, 16-23 are red, 8-15 are green, 0-7 are blue). The imageType will be TYPE_INT_RGB.
      Returns:
      the RGB value of the colour.
    • average

      public static Colour average​(Colour... colours)
      Calculate the average between any number of colours.
      Parameters:
      colours - The colours whose average to calculate.
      Returns:
      The average colour of the given colours.