11package org .openpatch .scratch .extensions .color ;
22
33/**
4- * The Color class represents a color in the Scratch environment. It supports
5- * various
6- * functionalities such as setting color values in the RGB and HSB spectrum,
7- * changing the color
4+ * The Color class represents a color in the Scratch environment. It supports various
5+ * functionalities such as setting color values in the RGB and HSB spectrum, changing the color
86 * based on a hue value, and converting between RGB and HSB color codes.
97 */
108public class Color {
@@ -18,8 +16,7 @@ public class Color {
1816 private double l = 255 ;
1917
2018 /** Constructs a new Color object with default values. */
21- public Color () {
22- }
19+ public Color () {}
2320
2421 public Color (String hexCode ) {
2522 if (hexCode .startsWith ("#" )) {
@@ -68,28 +65,21 @@ public Color(Color c) {
6865
6966 /**
7067 * Get the color value as a hex code. This is useful for comparing pixels.
71- *
68+ *
7269 * @see Stage#getBackgroundPixels()
73- *
7470 * @return hex code
7571 */
7672 public int get () {
7773 var v1 = this .r ;
7874 var v2 = this .g ;
7975 var v3 = this .b ;
8076
81- if (v1 > 255 )
82- v1 = 255 ;
83- else if (v1 < 0 )
84- v1 = 0 ;
85- if (v2 > 255 )
86- v2 = 255 ;
87- else if (v2 < 0 )
88- v2 = 0 ;
89- if (v3 > 255 )
90- v3 = 255 ;
91- else if (v3 < 0 )
92- v3 = 0 ;
77+ if (v1 > 255 ) v1 = 255 ;
78+ else if (v1 < 0 ) v1 = 0 ;
79+ if (v2 > 255 ) v2 = 255 ;
80+ else if (v2 < 0 ) v2 = 0 ;
81+ if (v3 > 255 ) v3 = 255 ;
82+ else if (v3 < 0 ) v3 = 0 ;
9383
9484 return 0xff000000 | ((int ) v1 << 16 ) | ((int ) v2 << 8 ) | (int ) v3 ;
9585 }
@@ -104,8 +94,7 @@ public double getHSB() {
10494 }
10595
10696 /**
107- * Setting the color value after the HSB spectrum. Saturation and Luminosity are
108- * fixed at 255.
97+ * Setting the color value after the HSB spectrum. Saturation and Luminosity are fixed at 255.
10998 *
11099 * @param h A hue value [0...255]
111100 */
@@ -165,8 +154,7 @@ public void setRGB(double r, double g, double b) {
165154 }
166155
167156 /**
168- * Changes the color accordining to a hue value, which is added to the current
169- * hue value. When the
157+ * Changes the color accordining to a hue value, which is added to the current hue value. When the
170158 * resulting value is greater than 255 it will be reset. For example: 285 => 30.
171159 *
172160 * @param h A hue value. Could be any positive or negative number.
@@ -185,9 +173,10 @@ public void changeColor(double h) {
185173 * @return hsb values
186174 */
187175 private static double [] RGBtoHSB (double r , double g , double b ) {
188- var hsb = java .awt .Color .RGBtoHSB (
189- Math .round ((float ) r ), Math .round ((float ) g ), Math .round ((float ) b ), null );
190- double [] hsbd = { hsb [0 ], hsb [1 ], hsb [2 ] };
176+ var hsb =
177+ java .awt .Color .RGBtoHSB (
178+ Math .round ((float ) r ), Math .round ((float ) g ), Math .round ((float ) b ), null );
179+ double [] hsbd = {hsb [0 ], hsb [1 ], hsb [2 ]};
191180 return hsbd ;
192181 }
193182
@@ -200,7 +189,8 @@ private static double[] RGBtoHSB(double r, double g, double b) {
200189 * @return rgb values
201190 */
202191 private static double [] HSBtoRGB (double h , double s , double l ) {
203- java .awt .Color colorRgb = new java .awt .Color (java .awt .Color .HSBtoRGB ((float ) h , (float ) s , (float ) l ));
192+ java .awt .Color colorRgb =
193+ new java .awt .Color (java .awt .Color .HSBtoRGB ((float ) h , (float ) s , (float ) l ));
204194 double [] rgb = new double [3 ];
205195 rgb [0 ] = colorRgb .getRed ();
206196 rgb [1 ] = colorRgb .getGreen ();
0 commit comments