Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 29, 2024
1 parent e7f7a31 commit ff20ef8
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/org/openpatch/scratch/extensions/color/Color.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.openpatch.scratch.extensions.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
* 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.
*/
public class Color {
Expand All @@ -18,8 +16,7 @@ public class Color {
private double l = 255;

/** Constructs a new Color object with default values. */
public Color() {
}
public Color() {}

public Color(String hexCode) {
if (hexCode.startsWith("#")) {
Expand Down Expand Up @@ -68,28 +65,21 @@ public Color(Color c) {

/**
* Get the color value as a hex code. This is useful for comparing pixels.
*
*
* @see Stage#getBackgroundPixels()
*
* @return hex code
*/
public int get() {
var v1 = this.r;
var v2 = this.g;
var v3 = this.b;

if (v1 > 255)
v1 = 255;
else if (v1 < 0)
v1 = 0;
if (v2 > 255)
v2 = 255;
else if (v2 < 0)
v2 = 0;
if (v3 > 255)
v3 = 255;
else if (v3 < 0)
v3 = 0;
if (v1 > 255) v1 = 255;
else if (v1 < 0) v1 = 0;
if (v2 > 255) v2 = 255;
else if (v2 < 0) v2 = 0;
if (v3 > 255) v3 = 255;
else if (v3 < 0) v3 = 0;

return 0xff000000 | ((int) v1 << 16) | ((int) v2 << 8) | (int) v3;
}
Expand All @@ -104,8 +94,7 @@ public double getHSB() {
}

/**
* Setting the color value after the HSB spectrum. Saturation and Luminosity are
* fixed at 255.
* Setting the color value after the HSB spectrum. Saturation and Luminosity are fixed at 255.
*
* @param h A hue value [0...255]
*/
Expand Down Expand Up @@ -165,8 +154,7 @@ public void setRGB(double r, double g, double b) {
}

/**
* Changes the color accordining to a hue value, which is added to the current
* hue value. When the
* 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.
*
* @param h A hue value. Could be any positive or negative number.
Expand All @@ -185,9 +173,10 @@ public void changeColor(double h) {
* @return hsb values
*/
private static double[] RGBtoHSB(double r, double g, double b) {
var hsb = java.awt.Color.RGBtoHSB(
Math.round((float) r), Math.round((float) g), Math.round((float) b), null);
double[] hsbd = { hsb[0], hsb[1], hsb[2] };
var hsb =
java.awt.Color.RGBtoHSB(
Math.round((float) r), Math.round((float) g), Math.round((float) b), null);
double[] hsbd = {hsb[0], hsb[1], hsb[2]};
return hsbd;
}

Expand All @@ -200,7 +189,8 @@ private static double[] RGBtoHSB(double r, double g, double b) {
* @return rgb values
*/
private static double[] HSBtoRGB(double h, double s, double l) {
java.awt.Color colorRgb = new java.awt.Color(java.awt.Color.HSBtoRGB((float) h, (float) s, (float) l));
java.awt.Color colorRgb =
new java.awt.Color(java.awt.Color.HSBtoRGB((float) h, (float) s, (float) l));
double[] rgb = new double[3];
rgb[0] = colorRgb.getRed();
rgb[1] = colorRgb.getGreen();
Expand Down

0 comments on commit ff20ef8

Please sign in to comment.