SBPaletteDiscrete#

This class is a base class for discrete color palettes.

A discrete color palette is constructed based on a list of colors.

Note

You can find available default palettes in samson.SBPaletteDefaultPalette.

See also

Colorizing nodes

SAMSON SDK: SBDPaletteDiscrete

class samson.SBPaletteDiscrete(*args, **kwargs)#

Bases: SBPalette

This class is a base class for discrete color palettes.

Overloaded function.

  1. __init__(self: samson.SBPaletteDiscrete) -> None

Default constructor

  1. __init__(self: samson.SBPaletteDiscrete, colors: list[samson.SBColor], name: str = ‘’, reverse: bool = False) -> None

Constructs a discrete color palette with the given colors.

Parameters:
  • colors (list of samson.SBColor) – The list of samson.SBColor

  • name (str, default='') – A palette name

  • reverse (bool, default=False) – The reverse flag - whether the color palette is mirrored or not.

Examples

>>> discrete_palette = SBPaletteDiscrete([SBColor.blue, SBColor.white, SBColor.red])
  1. __init__(self: samson.SBPaletteDiscrete, palette: samson.SBPaletteDiscrete) -> None

Constructs a discrete color palette based on the given discrete color palette.

Parameters:

palette (samson.SBPaletteDiscrete) – Another discrete color palette

getColors(self: samson.SBPaletteDiscrete) list[samson.SBColor]#

Returns a list of colors.

Return type:

A list of samson.SBColor

getCycledColor(self: samson.SBPaletteDiscrete, v: int) samson.SBColor#

Returns SBColor based on the palette and a value v that will be cycled to be within the range [0, number of colors in the palette].

Parameters:

v (int) – An integer value based on which the resulting color is computed, the value will be cycled to be within the range [0, number of colors in the palette]

Returns:

A color.

Return type:

samson.SBColor

Examples

>>> palette = SBPaletteDefaultPalette.discreteOkabeIto
>>> color = palette.getCycledColor(2)
>>> print(color)
[0.337255, 0.705882, 0.913725, 1.000000]
getCycledColorVector(self: samson.SBPaletteDiscrete, v: int) list[float]#

Returns RGB color in a float vector based on the palette and a value v value that will be cycled to be within the range [0, number of colors in the palette].

Parameters:

v (int) – An integer value based on which the resulting color is computed, the value will be cycled to be within the range [0, number of colors in the palette]

Returns:

An rgba color.

Return type:

list of 4 floats (rgba)

Examples

>>> palette = SBPaletteDefaultPalette.discreteOkabeIto
>>> color = palette.getCycledColorVector(2)
>>> print(color)
[0.337255, 0.705882, 0.913725, 1.000000]
property numberOfColors#

Returns the number of colors in the color palette.