Class Color

java.lang.Object
org.openpatch.scratch.extensions.color.Color

public class Color extends Object
The Color class represents a color in the Scratch environment. It supports various functionalities such as setting color values in the RGB and HSB spectrum, changing the color based on a hue value, and converting between RGB and HSB color codes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Color object with default values.
    Color(double h)
    Constructs a new Color object with the specified hue value.
    Color(double r, double g, double b)
    Constructs a new Color object with the specified rgb values.
    Color(String hexCode)
     
    Copies the received ScratchColor object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeColor(double h)
    Changes the color accordining to a hue value, which is added to the current hue value.
    int
    get()
    Get the color value as a hex code.
    double
    Get the blue value.
    double
    Get the green value.
    double
    Get the hue value.
    double
    Get the color value on the HSB spectrum.
    double
    Get the luminosity value.
    double
    Get the red value.
    double
    Get the saturation value.
    void
    setHSB(double h)
    Setting the color value after the HSB spectrum.
    void
    setHSB(double h, double s, double l)
    Setting the color value after the HSB spectrum.
    void
    setRGB(double r, double g, double b)
    Setting the color value after the RGB spectrum

    Methods inherited from class Object

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

    • Color

      public Color()
      Constructs a new Color object with default values.
    • Color

      public Color(String hexCode)
    • Color

      public Color(double h)
      Constructs a new Color object with the specified hue value.
      Parameters:
      h - the hue value
    • Color

      public Color(double r, double g, double b)
      Constructs a new Color object with the specified rgb values.
      Parameters:
      r - the red value
      g - the green value
      b - the blue value
    • Color

      public Color(Color c)
      Copies the received ScratchColor object.
      Parameters:
      c - ScratchColor object to copy
  • Method Details

    • get

      public int get()
      Get the color value as a hex code. This is useful for comparing pixels.
      Returns:
      hex code
    • getHSB

      public double getHSB()
      Get the color value on the HSB spectrum.
      Returns:
      hue value [0...255]
    • setHSB

      public void setHSB(double h)
      Setting the color value after the HSB spectrum. Saturation and Luminosity are fixed at 255.
      Parameters:
      h - A hue value [0...255]
    • setHSB

      public void setHSB(double h, double s, double l)
      Setting the color value after the HSB spectrum.
      Parameters:
      h - A hue value [0...255]
      s - A saturation value [0...255]
      l - A luminosity value [0...255]
    • setRGB

      public void setRGB(double r, double g, double b)
      Setting the color value after the RGB spectrum
      Parameters:
      r - A red value [0...255]
      g - A green value [0...255]
      b - A blue value [0...255]
    • changeColor

      public void changeColor(double h)
      Changes the color accordining to a hue value, which is added to the current hue value. When the resulting value is greater than 255 it will be reset. For example: 285 => 30.
      Parameters:
      h - A hue value. Could be any positive or negative number.
    • getRed

      public double getRed()
      Get the red value.
      Returns:
      red value [0...255]
    • getGreen

      public double getGreen()
      Get the green value.
      Returns:
      green value [0...255]
    • getBlue

      public double getBlue()
      Get the blue value.
      Returns:
      blue value [0...255]
    • getH

      public double getH()
      Get the hue value.
      Returns:
      hue value [0...255]
    • getS

      public double getS()
      Get the saturation value.
      Returns:
      saturation value [0...255]
    • getL

      public double getL()
      Get the luminosity value.
      Returns:
      luminosity value [0...255]