Class Color
java.lang.Object
org.openpatch.scratch.extensions.color.Color
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeColor(double h) Changes the color accordining to a hue value, which is added to the current hue value.intget()Get the color value as a hex code.doublegetBlue()Get the blue value.doublegetGreen()Get the green value.doublegetH()Get the hue value.doublegetHSB()Get the color value on the HSB spectrum.doublegetL()Get the luminosity value.doublegetRed()Get the red value.doublegetS()Get the saturation value.voidsetHSB(double h) Setting the color value after the HSB spectrum.voidsetHSB(double h, double s, double l) Setting the color value after the HSB spectrum.voidsetRGB(double r, double g, double b) Setting the color value after the RGB spectrum
-
Constructor Details
-
Color
public Color()Constructs a new Color object with default values. -
Color
-
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 valueg- the green valueb- the blue value
-
Color
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]
-