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
-
alpha
¶ alpha component
-
black
= [0.000000, 0.000000, 0.000000, 1.000000]¶
-
blue
= [0.000000, 0.000000, 1.000000, 1.000000]¶
-
cyan
= [0.000000, 1.000000, 1.000000, 1.000000]¶
-
green
= [0.000000, 1.000000, 0.000000, 1.000000]¶
-
isSerializable
¶ Returns true when the class is serializable
-
magenta
= [1.000000, 0.000000, 1.000000, 1.000000]¶
-
red
= [1.000000, 0.000000, 0.000000, 1.000000]¶
-
white
= [1.000000, 1.000000, 1.000000, 1.000000]¶
-
yellow
= [1.000000, 1.000000, 0.000000, 1.000000]¶