Class ColorPalette

java.lang.Object
com.github.darksoulq.abyssallib.common.color.ColorPalette
All Implemented Interfaces:
Iterable<org.bukkit.Color>

public class ColorPalette extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    static final ColorPalette
    A predefined palette containing high-saturation, vibrant neon colors.
    static final ColorPalette
    A predefined palette containing soft, high-lightness pastel colors.
    static final ColorPalette
    A predefined palette representing the standard colors of a rainbow.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ColorPalette(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 Type
    Method
    Description
    org.bukkit.Color
    Calculates the mathematical average of all colors in this palette.
    org.bukkit.Color
    closest(org.bukkit.Color target)
    Finds the color in this palette that is mathematically closest to the target.
    fromImage(BufferedImage image, int maxColors)
    Creates a palette by sampling colors from a BufferedImage.
    generate(org.bukkit.Color start, org.bukkit.Color end, int steps)
    Generates a gradient palette between two colors.
    org.bukkit.Color
    get(int index)
    Retrieves a color by its index.
    @NotNull Iterator<org.bukkit.Color>
    Returns an iterator over the colors in this palette.
    org.bukkit.Color
    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 a ColorProvider for procedural color retrieval.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Iterable

    forEach, spliterator
  • Field Details

    • PASTEL

      public static final ColorPalette PASTEL
      A predefined palette containing soft, high-lightness pastel colors.
    • NEON

      public static final ColorPalette NEON
      A predefined palette containing high-saturation, vibrant neon colors.
    • RAINBOW

      public static final ColorPalette 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 - The Color objects to include.
    • ColorPalette

      public ColorPalette(Collection<org.bukkit.Color> colors)
      Constructs a palette from an existing collection of colors.
      Parameters:
      colors - A Collection of Color objects.
  • Method Details

    • fromImage

      public static ColorPalette fromImage(BufferedImage image, int maxColors)
      Creates a palette by sampling colors from a BufferedImage.
      Parameters:
      image - The source image to analyze.
      maxColors - The maximum number of unique colors to extract.
      Returns:
      A new ColorPalette based on the image's colors.
    • generate

      public static ColorPalette generate(org.bukkit.Color start, org.bukkit.Color end, int steps)
      Generates a gradient palette between two colors.
      Parameters:
      start - The starting Color.
      end - The ending Color.
      steps - The number of colors to generate in the transition.
      Returns:
      A new ColorPalette representing 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 Color at the calculated index.
    • random

      public org.bukkit.Color random()
      Selects a random color from the palette.
      Returns:
      A random Color from this palette, or Color.WHITE if 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 Color found in this palette.
    • average

      public org.bukkit.Color average()
      Calculates the mathematical average of all colors in this palette.
      Returns:
      The averaged Color.
    • sort

      public ColorPalette sort(Comparator<org.bukkit.Color> comparator)
      Returns a new ColorPalette sorted by the provided comparator.
      Parameters:
      comparator - The Comparator used to define color order.
      Returns:
      A new sorted ColorPalette.
    • toProvider

      public ColorProvider toProvider()
      Converts this palette into a ColorProvider for procedural color retrieval.
      Returns:
      A ColorProvider configured with this palette's colors.
    • iterator

      @NotNull public @NotNull Iterator<org.bukkit.Color> iterator()
      Returns an iterator over the colors in this palette.
      Specified by:
      iterator in interface Iterable<org.bukkit.Color>
      Returns:
      An Iterator.