Merge pull request #7739 from deathbeam/use-hsl

Use HSB instead of RGBA to generate color from object
This commit is contained in:
Adam
2019-02-07 07:26:21 -05:00
committed by GitHub
2 changed files with 4 additions and 8 deletions

View File

@@ -474,7 +474,7 @@ public class PartyPlugin extends Plugin implements KeyListener
worldMapManager.add(worldMapPoint); worldMapManager.add(worldMapPoint);
} }
return new PartyData(u, name, worldMapPoint, ColorUtil.fromObject(name, true)); return new PartyData(u, name, worldMapPoint, ColorUtil.fromObject(name));
}); });
} }

View File

@@ -231,16 +231,12 @@ public class ColorUtil
/** /**
* Creates color from passed object hash code * Creates color from passed object hash code
* @param object object with hashCode * @param object object with hashCode
* @param skipAlpha skips alpha
* @return color * @return color
*/ */
public static Color fromObject(@Nonnull final Object object, boolean skipAlpha) public static Color fromObject(@Nonnull final Object object)
{ {
int i = object.hashCode(); int i = object.hashCode();
int r = (i >> 24) & 0xFF; float h = (i % 360) / 360f;
int g = (i >> 16) & 0xFF; return Color.getHSBColor(h, 1, 1);
int b = (i >> 8) & 0xFF;
int a = i & 0xFF;
return new Color(r, g, b, skipAlpha ? 255 : a);
} }
} }