Overview and Key Concepts
A Color Palette is a list of colors. Each color can be associated with a value. You can then look up a color using the value associated with that color, using the Color.fromPalette() method.
You can access Color Palettes in the toolbox.
Assigning Values to Colors
In order to access a color from a Color Palette, you must first assign a value to that color. The value can one of the following types of values:
- an array containing number, text, or node values
You can access a palette's colors through the Color.fromPalette() method. The most common way to use this method is to pass in a value and the name of a palette. The palette will look up the color associated with the given value, and return that color.
If the palette does not have a color assigned to the given value, then the palette will look for any colors that don't have a value assigned yet. If one exists, then the palette will assign the color to the given value and return the color. If there are no unused colors, then the color palette will generate a color, assign the given value to the new color, and return the new color.
Using a Gradient
A gradient allows you to assign colors to continuous values:
The gradient is defined by the set of colors that are assigned to number values. Each of these colors becomes a color stop in the gradient. If you call Color.fromPalette(), passing in a number value and a gradient palette, then that palette will interpolate between assigned colors to return the correct color. The following table shows the colors that would be returned from the palette shown above:
When a palette interpolates to find a color, it does not assign that value to the interpolated color. This way, the list of colors remains constant.
The Color Palette has the following properties:
You can use this property to edit the name of the palette. You can also use this property to change which palette you are viewing.
If you check this box, the color palette will use the assigned number values to form a gradient. A gradient editor field will appear, allowing you to change the locations of the color stops.
This button opens a menu. The menu contains options to edit many or all colors and values simultaneously.
This property shows the list of colors known to the palette, and also which value is assigned to each color. This list allows you to perform the following operations:
- You can edit the value assigned to each color.
- You can edit the given color.
- You can remove a color.
- You can reorder the colors. This has no effect on the Color Palette's logic, but it can sometimes be helpful to group certain colors/values together.