Class Color
java.lang.Object
org.openpatch.scratch.Color
A colour. Colours never change:
withHue(…) and the other with methods return a
new colour, so a colour can be shared, kept in a constant (HtmlColor) or handed to
several sprites without one of them changing it for the others.
A colour can be given in two ways:
- red, green and blue from 0 to 255, plus an optional alpha (opacity) from 0 to 255:
new Color(255, 128, 0); - Scratch's colour, saturation and brightness, each from 0 to 100:
Color.fromHSB(50, 100, 100). The colour (hue) goes around: 0 is red, about 17 yellow, 33 green, 50 cyan, 67 blue, 83 magenta, 100 red again.
Color orange = new Color(255, 128, 0);
Color lighter = orange.withBrightness(100).withSaturation(50);
Color next = orange.withHue(orange.getHue() + 10);
-
Constructor Summary
ConstructorsConstructorDescriptionColor(double red, double green, double blue) A colour from red, green and blue, each from 0 to 255 (values outside are clamped).Color(double red, double green, double blue, double alpha) A colour from red, green, blue and alpha, each from 0 to 255 (values outside are clamped).A colour from a hex code as in HTML and CSS:"#ff8000","ff8000","#f80", or with alpha"#ff800080". -
Method Summary
Modifier and TypeMethodDescriptionbooleanTwo colours are equal when they pack into the same ARGB number.static ColorfromARGB(int argb) A colour from a packed ARGB number, astoARGB()gives it.static ColorfromHSB(double hue, double saturation, double brightness) A colour from Scratch's colour, saturation and brightness, each from 0 to 100.doublegetAlpha()doublegetBlue()doubledoublegetGreen()doublegetHue()doublegetRed()doubleinthashCode()inttoARGB()The colour packed into one int as alpha, red, green and blue (8 bits each, rounded), the way pixels are stored.toString()withAlpha(double alpha) withBlue(double blue) withBrightness(double brightness) withGreen(double green) withHue(double hue) Another colour (hue), keeping saturation, brightness and alpha.withRed(double red) withSaturation(double saturation)
-
Constructor Details
-
Color
public Color(double red, double green, double blue) A colour from red, green and blue, each from 0 to 255 (values outside are clamped). The colour is opaque.- Parameters:
red- red from 0 to 255green- green from 0 to 255blue- blue from 0 to 255
-
Color
public Color(double red, double green, double blue, double alpha) A colour from red, green, blue and alpha, each from 0 to 255 (values outside are clamped). An alpha of 0 is invisible, 255 opaque.- Parameters:
red- red from 0 to 255green- green from 0 to 255blue- blue from 0 to 255alpha- opacity from 0 to 255
-
Color
A colour from a hex code as in HTML and CSS:"#ff8000","ff8000","#f80", or with alpha"#ff800080".- Parameters:
hex- the hex code
-
-
Method Details
-
fromHSB
A colour from Scratch's colour, saturation and brightness, each from 0 to 100. The colour goes around (110 is the same as 10); saturation and brightness are clamped.- Parameters:
hue- the colour from 0 to 100saturation- from 0 (grey) to 100 (full colour)brightness- from 0 (black) to 100 (full brightness)- Returns:
- the colour
-
fromARGB
-
getRed
public double getRed()- Returns:
- red from 0 to 255
-
getGreen
public double getGreen()- Returns:
- green from 0 to 255
-
getBlue
public double getBlue()- Returns:
- blue from 0 to 255
-
getAlpha
public double getAlpha()- Returns:
- alpha (opacity) from 0 (invisible) to 255 (opaque)
-
getHue
public double getHue()- Returns:
- Scratch's colour (hue) from 0 to 100; 0 for greys
-
getSaturation
public double getSaturation()- Returns:
- saturation from 0 (grey) to 100
-
getBrightness
public double getBrightness()- Returns:
- brightness from 0 (black) to 100
-
withRed
- Parameters:
red- red from 0 to 255- Returns:
- this colour with another red
-
withGreen
- Parameters:
green- green from 0 to 255- Returns:
- this colour with another green
-
withBlue
- Parameters:
blue- blue from 0 to 255- Returns:
- this colour with another blue
-
withAlpha
- Parameters:
alpha- opacity from 0 to 255- Returns:
- this colour with another alpha
-
withHue
Another colour (hue), keeping saturation, brightness and alpha. The colour goes around, sowithHue(getHue() + 10)works like Scratch's "change color by 10".- Parameters:
hue- the colour from 0 to 100- Returns:
- this colour with another hue
-
withSaturation
- Parameters:
saturation- from 0 to 100- Returns:
- this colour with another saturation
-
withBrightness
- Parameters:
brightness- from 0 to 100- Returns:
- this colour with another brightness
-
toARGB
public int toARGB()The colour packed into one int as alpha, red, green and blue (8 bits each, rounded), the way pixels are stored.- Returns:
- the packed colour
-
toString
-
equals
-
hashCode
-