Color¶
This class describes a color and can be used to colorize e.g. atoms individually.
Let’s colorize atoms in the active document based on their position (x-coordinate).
# get all atom nodes
indexer = SAMSON.getNodes('node.type atom')
# perform a colorization of atoms, if the indexer contains any atoms
if indexer.size > 0:
# [optional] notify the user that SAMSON is busy
# this will set a message in the SAMSON's status bar
SAMSON.setBusy(True)
# set an initial value for minimal and maximal coordinates
# equal to the x-coordinate's value of the first atom
minx = maxx = indexer[0].getPosition().x.value
# compute minimal and maximal x-coordinates
for atom in indexer: # loop over atoms in the indexer
# get the x-coordinate's value of the atom
x = atom.getPosition().x.value
if x > maxx: maxx = x
if x < minx: minx = x
# colorize each atom based on its x-coordinate
for atom in indexer: # loop over atoms in the indexer
# get the x-coordinate's value of the atom
x = atom.getPosition().x.value
# normalize based on minimal and maximal x-coordinates
xc = (x - minx) / (maxx - minx)
# get RGB color for a node based on HSV color
color = sam.DataModel.Type.Color.fromHSV(239.5 / 360.0 * xc, 205.0/255.0, 1.0)
# set the color of the atom node
atom.setColor(color)
# SAMSON is not busy anymore
SAMSON.setBusy(False)
For colorization using color schemes please refer to samson.DataModel.DataGraph.ColorPalette
and samson.DataModel.DataGraph.ColorScheme
.
See also
SAMSON API: SBDTypeColor
- class samson.DataModel.Type.Color(*args, **kwargs)¶
Bases:
pybind11_builtins.pybind11_object
This class describes a color.
Overloaded function.
__init__(self: samson.DataModel.Type.Color) -> None
Constructs a color (1.0, 1.0, 1.0, 1.0)
__init__(self: samson.DataModel.Type.Color, red: float, green: float, blue: float, alpha: float = 1.0) -> None
Constructs a color (red, green, blue, alpha). Arguments should be in the range [0.0, 1.0].
- Args:
red (float): red component of RGB-color
green (float): green component of RGB-color
blue (float): blue component of RGB-color
alpha (float): alpha component (transparency)
__init__(self: samson.DataModel.Type.Color, red: int, green: int, blue: int, alpha: int = 255) -> None
Constructs a color (red, green, blue, alpha). Arguments should be in the range [0, 255].
- Args:
red (int): red component of RGB-color
green (int): green component of RGB-color
blue (int): blue component of RGB-color
alpha (int): alpha component (transparency)
__init__(self: samson.DataModel.Type.Color, c: samson.DataModel.Type.Color) -> None
Constructs a color based on another color c.
- static fromHCL(hue: float, chroma: float, luminance: float) samson.DataModel.Type.Color ¶
Creates a color from a given HCL (CIE LCh_uv) color
- static fromHSV(hue: float, saturation: float, value: float) samson.DataModel.Type.Color ¶
Creates a color from a given HSV color
- getColor(self: samson.DataModel.Type.Color) List[float] ¶
Stores the four components as a float array
- printDebugInfo(self: samson.DataModel.Type.Color, offset: int = 0) None ¶
Prints some debugging information in stdout
- toString(self: samson.DataModel.Type.Color) str ¶
A string representation
- property alpha¶
alpha component, the value is in the [0.0, 1.0] interval
- property alphaInt¶
alpha component, the value is in the [0, 255] interval
- black = [0,000000, 0,000000, 0,000000, 1,000000]¶
- blue = [0,000000, 0,000000, 1,000000, 1,000000]¶
- property blueInt¶
blue component, the value is in the [0, 255] interval
- cyan = [0,000000, 1,000000, 1,000000, 1,000000]¶
- defaultKeyframeColor = [0,800000, 0,898039, 1,000000, 1,000000]¶
- globalXAxis = [0,878431, 0,380392, 0,227451, 1,000000]¶
- globalYAxis = [0,309804, 0,741176, 0,396078, 1,000000]¶
- globalZAxis = [0,290196, 0,556863, 0,929412, 1,000000]¶
- green = [0,000000, 1,000000, 0,000000, 1,000000]¶
- property greenInt¶
green component, the value is in the [0, 255] interval
- property isSerializable¶
Returns true when the class is serializable
- localXAxis = [0,949020, 0,976471, 1,000000, 1,000000]¶
- localYAxis = [0,800000, 0,898039, 1,000000, 1,000000]¶
- localZAxis = [0,650980, 0,823529, 1,000000, 1,000000]¶
- magenta = [1,000000, 0,000000, 1,000000, 1,000000]¶
- orange = [1,000000, 0,588235, 0,172549, 1,000000]¶
- red = [1,000000, 0,000000, 0,000000, 1,000000]¶
- property redInt¶
red component, the value is in the [0, 255] interval
- white = [1,000000, 1,000000, 1,000000, 1,000000]¶
- yellow = [1,000000, 1,000000, 0,000000, 1,000000]¶