Class ColorPalette
java.lang.Object
com.github.darksoulq.abyssallib.common.color.ColorPalette
- All Implemented Interfaces:
Iterable<org.bukkit.Color>
Represents a collection of
Color objects, providing utility methods for
color selection, palette generation, and mathematical analysis.
This class is useful for managing specific aesthetic themes, generating gradients, or sampling colors from external assets like images.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ColorPaletteA predefined palette containing high-saturation, vibrant neon colors.static final ColorPaletteA predefined palette containing soft, high-lightness pastel colors.static final ColorPaletteA predefined palette representing the standard colors of a rainbow. -
Constructor Summary
ConstructorsConstructorDescriptionColorPalette(Collection<org.bukkit.Color> colors) Constructs a palette from an existing collection of colors.ColorPalette(org.bukkit.Color... colors) Constructs a palette from a variable number of Color arguments. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.Coloraverage()Calculates the mathematical average of all colors in this palette.org.bukkit.Colorclosest(org.bukkit.Color target) Finds the color in this palette that is mathematically closest to the target.static ColorPalettefromImage(BufferedImage image, int maxColors) Creates a palette by sampling colors from aBufferedImage.static ColorPalettegenerate(org.bukkit.Color start, org.bukkit.Color end, int steps) Generates a gradient palette between two colors.org.bukkit.Colorget(int index) Retrieves a color by its index.@NotNull Iterator<org.bukkit.Color> iterator()Returns an iterator over the colors in this palette.org.bukkit.Colorrandom()Selects a random color from the palette.sort(Comparator<org.bukkit.Color> comparator) Returns a new ColorPalette sorted by the provided comparator.Converts this palette into aColorProviderfor procedural color retrieval.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
PASTEL
A predefined palette containing soft, high-lightness pastel colors. -
NEON
A predefined palette containing high-saturation, vibrant neon colors. -
RAINBOW
A predefined palette representing the standard colors of a rainbow.
-
-
Constructor Details
-
ColorPalette
public ColorPalette(org.bukkit.Color... colors) Constructs a palette from a variable number of Color arguments.- Parameters:
colors- TheColorobjects to include.
-
ColorPalette
Constructs a palette from an existing collection of colors.- Parameters:
colors- ACollectionofColorobjects.
-
-
Method Details
-
fromImage
Creates a palette by sampling colors from aBufferedImage.- Parameters:
image- The source image to analyze.maxColors- The maximum number of unique colors to extract.- Returns:
- A new
ColorPalettebased on the image's colors.
-
generate
Generates a gradient palette between two colors.- Parameters:
start- The startingColor.end- The endingColor.steps- The number of colors to generate in the transition.- Returns:
- A new
ColorPaletterepresenting the gradient.
-
get
public org.bukkit.Color get(int index) Retrieves a color by its index. This method wraps around using modulo arithmetic if the index exceeds the palette size.- Parameters:
index- The index to retrieve.- Returns:
- The
Colorat the calculated index.
-
random
public org.bukkit.Color random()Selects a random color from the palette.- Returns:
- A random
Colorfrom this palette, orColor.WHITEif empty.
-
closest
public org.bukkit.Color closest(org.bukkit.Color target) Finds the color in this palette that is mathematically closest to the target.- Parameters:
target- The color to compare against.- Returns:
- The closest
Colorfound in this palette.
-
average
public org.bukkit.Color average()Calculates the mathematical average of all colors in this palette.- Returns:
- The averaged
Color.
-
sort
Returns a new ColorPalette sorted by the provided comparator.- Parameters:
comparator- TheComparatorused to define color order.- Returns:
- A new sorted
ColorPalette.
-
toProvider
Converts this palette into aColorProviderfor procedural color retrieval.- Returns:
- A
ColorProviderconfigured with this palette's colors.
-
iterator
-