Class LXPalette

java.lang.Object
heronarts.lx.LXComponent
heronarts.lx.color.LXPalette
All Implemented Interfaces:
LXLoopTask, LXPath, LXSerializable, LXOscComponent, LXParameterListener

public class LXPalette extends LXComponent implements LXLoopTask, LXOscComponent
A palette is an object that is used to keep track of top-level color values and set modes of color computation. Though its use is not required, it is very useful for creating coherent color schemes across patterns.
  • Field Details

  • Constructor Details

    • LXPalette

      public LXPalette(LX lx)
  • Method Details

    • onParameterChanged

      public void onParameterChanged(LXParameter p)
      Description copied from class: LXComponent
      Subclasses are free to override this if desired. It will automatically fire for any listenable parameter that is registered with this component.
      Specified by:
      onParameterChanged in interface LXParameterListener
      Overrides:
      onParameterChanged in class LXComponent
      Parameters:
      p - Parameter that has a value change
    • getColor

      public int getColor()
      Gets the primary color of the currently active swatch
      Returns:
      Primary color of active swatch
    • getSwatchColor

      public LXDynamicColor getSwatchColor(int index)
      Gets the color in the active swatch at the given index. If the swatch doesn't have that many colors, the last available color is returned.
      Parameters:
      index - Index in swatch
      Returns:
      Color
    • getHuef

      public float getHuef()
      Gets the hue of the primary color in active swatch
      Returns:
      Hue of primary color
    • getHue

      public double getHue()
      Gets the hue of the primary color in active swatch
      Returns:
      Hue of primary color
    • getSaturationf

      public float getSaturationf()
      Gets the saturation of the primary color in active swatch
      Returns:
      Saturation of primary color
    • getSaturation

      public double getSaturation()
      Gets the saturation of the primary color in active swatch
      Returns:
      Saturation of primary color
    • getBrightnessf

      public float getBrightnessf()
      Gets the brightness of the primary color in active swatch
      Returns:
      Brightness of primary color
    • getBrightness

      public double getBrightness()
      Gets the brightness of the primary color in active swatch
      Returns:
      Brightness of primary color
    • saveSwatch

      public LXSwatch saveSwatch()
      Saves the current swatch to the list of saved swatches
      Returns:
      Saved swatch, added to swatch list
    • addSwatch

      public LXSwatch addSwatch(JsonObject swatchObj, int index)
      Adds a swatch at the given index
      Parameters:
      swatchObj - Saved swatch object
      index - Index to save at
      Returns:
      Swatch object
    • removeSwatch

      public LXPalette removeSwatch(LXSwatch swatch)
      Removes a swatch from the color palette's saved swatch list
      Parameters:
      swatch - Swatch to remove
      Returns:
      this
    • setSwatch

      public boolean setSwatch(LXSwatch swatch)
      Set the palette to a saved swatch
      Parameters:
      swatch - Swatch to transition to
      Returns:
      Whether swatch was set, or false if already in transition
    • getTransitionProgress

      public double getTransitionProgress()
    • getAutoCycleProgress

      public double getAutoCycleProgress()
    • loop

      public void loop(double deltaMs)
      Specified by:
      loop in interface LXLoopTask
    • moveSwatch

      public LXPalette moveSwatch(LXSwatch swatch, int index)
      Moves a saved swatch to a different position in the list
      Parameters:
      swatch - Saved swatch
      index - New index for that swatch
      Returns:
      this
    • addListener

      public LXPalette addListener(LXPalette.Listener listener)
      Registers a listener to the palette
      Parameters:
      listener - Palette listener
      Returns:
      this
    • removeListener

      public LXPalette removeListener(LXPalette.Listener listener)
      Unregisters a listener to the palette
      Parameters:
      listener - Palette listener
      Returns:
      this
    • handleOscMessage

      public boolean handleOscMessage(OscMessage message, String[] parts, int index)
      Description copied from class: LXComponent
      Handles an OSC message sent to this component. By default this method handles registered components and parameters, but subclasses may override this method to handle different types of OSC messages.
      Specified by:
      handleOscMessage in interface LXOscComponent
      Overrides:
      handleOscMessage in class LXComponent
      Parameters:
      message - Full OSC message object
      parts - The OSC address pattern, broken into an array of parts
      index - Which index into the parts array corresponds to this component's children
      Returns:
      true if the OSC message was handled and should be considered consumed, false otherwise
    • dispose

      public void dispose()
      Description copied from class: LXComponent
      Invoked when a component is being removed from the system and will no longer be used at all. This unregisters the component and should free up any resources and parameter listeners. Ideally after this method is called the object should be eligible for garbage collection. Subclasses are generally expected to override this method to handle their particular cleanup work. They should also generally call super.dispose() at the appropriate time to perform the basic cleanup, which may need to happen either before or after cleaning up other objects.
      Overrides:
      dispose in class LXComponent
    • save

      public void save(LX lx, JsonObject obj)
      Description copied from class: LXComponent
      Serializes the LX component. By default, all internal and user-facing parameters are serialized, as well as any explicitly registered child components. Note that child arrays are not serialized, or any other dynamic components. Subclasses may override to perform more saving, and are expected to call super.save(lx, obj) at the appropriate time.
      Specified by:
      save in interface LXSerializable
      Overrides:
      save in class LXComponent
      Parameters:
      lx - LX instance
      obj - Object to serialize into
    • load

      public void load(LX lx, JsonObject obj)
      Description copied from class: LXComponent
      Loads the LX component. Restores the ID of the component, as well as its internal and user-facing parameters. Any explicitly registered children will be automatically loaded, so long as they are direct descendants. Dynamic arrays will not be automatically loaded, this is left to subclasses to implement.
      Specified by:
      load in interface LXSerializable
      Overrides:
      load in class LXComponent
      Parameters:
      lx - LX instance
      obj - Object to deserialize
    • exportSwatches

      public void exportSwatches(File file)
    • importSwatches

      public List<LXSwatch> importSwatches(File file)