Class Colors

java.lang.Object
org.opentrafficsim.draw.Colors

public final class Colors extends Object
List of colors to use for various legends.

Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Peter Knoppers, Wouter Schakel
  • Field Details

    • GREEN_RED

      public static final Color[] GREEN_RED
      3-color scale from green to red.
    • GREEN_RED_DARK

      public static final Color[] GREEN_RED_DARK
      5-color scale from green to red with dark edges.
    • ULTRA

      public static final Color[] ULTRA
      6-color scale from magenta, through red-green, to blue.
    • ENUMERATE

      public static final Color[] ENUMERATE
      10-color scale for enumeration.
    • ENUMERATE_NAMES

      public static final String[] ENUMERATE_NAMES
      Names of the enumerated colors.
  • Method Details

    • reverse

      public static Color[] reverse(Color[] colors)
      Reverses the color array.
      Parameters:
      colors - array of colors
      Returns:
      reversed color array
    • hue

      public static Color[] hue(int n)
      Creates an array of n colors with varying hue.
      Parameters:
      n - number of colors.
      Returns:
      array of n colors with varying hue
    • getEnumerated

      public static Color getEnumerated(int index)
      Returns a color for the index. Modulo is applied for indices outside of the normal range.
      Parameters:
      index - index.
      Returns:
      color for index.
    • nameEnumerated

      public static String nameEnumerated(int index)
      Returns the name of a color for the index. Modulo is applied for indices outside of the normal range.
      Parameters:
      index - index.
      Returns:
      name of color for index.
    • getIdColor

      public static Color getIdColor(String id, Color[] colors)
      Returns a color from an array, where the used index is determined based on the id. If the last character of the id is a digit, that value is used. Otherwise it is the absolute hash code of the id. The modulo of either of these values given the number of colors is the index in the array of the color returned.
      Parameters:
      id - object id
      colors - colors to select from
      Returns:
      color