OMC::PaletteColour Class Reference

Detailed Description

Provides methods to access palette colour objects and their gradient positions.

A palette colour can behave as a solid colour, a linear gradial or a radial gradient. When a palette colour is a gradient, it provides colour values at relative positions in the gradient.


A Simple Example - Creating a new solid palette colour on the project, and interacting with it.

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Create a new colour palette (it already comes with a default name and colour):
newPaletteType = 'Colour'
newPaletteName = 'Colour_Palette_Name'
newColourPalette = palette_list.create(newPaletteType,newPaletteName)
# Create a new solid red palette colour:
newColourName = 'Red_Colour'
newSolidRedPaletteColour = newColourPalette.create_solid_colour(newColourName,[255,0,0,255])
# Check its red value as a solid colour:
print(newSolidRedPaletteColour.r) #255
# Change its type:
newSolidRedPaletteColour.type = 'linear_gradient'
# Check the gradient colour position percentages (read only values):
print(newSolidRedPaletteColour[0].position) #0.0
print(newSolidRedPaletteColour[1].position) #100.0
# Change the gradient to start at red and end in blue (by substituting the end colour):
newSolidRedPaletteColour[1] = harmony.Colour([0,0,255,255])
# Get the color at the middle position, without adding a colour marker:
middleColor = newSolidRedPaletteColour.interpolate(50)
print(middleColor.r) #127
print(middleColor.b) #127
# Insert the color at the middle position:
newSolidRedPaletteColour.add(middleColor)
# List the colors on the gradient:
for gradientColour in newSolidRedPaletteColour.list():
print([gradientColour.r,gradientColour.g,gradientColour.b])
#[255, 0, 0]
#[127, 0, 127]
#[ 0, 0, 255]

Public Member Functions

bool contains (OMC::Colour colour)
 Identifies if the list contains the given colour. Item can be a 3 RGB or 4 RGBA array, a OMC::Color or a OMC::PaletteGradientPosition. More...
 
Array [OMC::PaletteGradientPositionlist ()
 Converts the dynamic list into a concrete list of palette gradient position objects. More...
 
OMC::PaletteGradientPosition add (OMC::Colour colour, float percentage)
 Adds a colour to the gradient. The input can also be a OMC::Color or OMC::PaletteGradientPosition. More...
 
OMC::PaletteGradientPosition interpolate (float percentage)
 Returns a gradient position at the interpolated position. More...
 
OMC::PaletteGradientPosition pop (int index)
 Pops given index object from this Palette colours. More...
 
void remove (OMC::PaletteGradientPosition gradientPosition)
 Remove a colour position from the gradient. Throws error if unsuccessful. More...
 
void clear ()
 Clear all colours from the object. Throws error if unsuccessful. More...
 
OMC::PaletteListpalette_list ()
 Gets the parent palette list, or throws error if currently parentless. More...
 
OMC::Palettepalette ()
 Gets the parent palette, or throws error if currently parentless. More...
 

Public Attributes

OMC::PaletteGradientPosition operator[int index]
 Provides the PaletteGradientPosition object at the given index. Note: setting value-type properties on the returned object will not take effect on this container object, since they are a copy and not the original object. More...
 
float r
 Get and set the red value of the colour 0-255. More...
 
float g
 Get and set the green value of the colour 0-255. More...
 
float b
 Get and set the blue value of the colour 0-255. More...
 
float a
 Get and set the alpha value of the colour 0-255. More...
 
double h
 Get and set the hue value of the colour 0-360. More...
 
double l
 Get and set the lightness value of the colour 0-100. More...
 
double s
 Get and set the saturation value of the colour 0-100. More...
 
QString hex
 Get and set the hex value of the colour in form #AARRGGBB. More...
 
OMC::Colour colour
 Get and set the colour object part of the gradient position. More...
 
QString type
 Provides the type of PaletteGradientPosition, can be either Solid, Linear or Radial Gradient. More...
 
QString name
 The color pot name. More...
 
QString base_type
 The base type of colour, either 'Colour' or 'Texture'. More...
 
QString id
 Unique ID of the color. More...
 
bool valid
 Get the validity of the object at the moment. More...
 

Member Function Documentation

◆ add()

OMC::PaletteGradientPosition OMC::PaletteColour::add ( OMC::Colour  colour,
float  percentage 
)

Adds a colour to the gradient. The input can also be a OMC::Color or OMC::PaletteGradientPosition.

Returns
The copy of the internally added color gradient object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_colour = new_colour_palette.create_linear_gradient_colour('Colour_A',[255,0,0])
# Add colours:
new_colour.add([0,255,255],25)
new_colour.add([255,0,255],50)
new_colour.add([255,255,0],75)
# List the colors on the gradient:
for gradientColour in new_colour:
print("Colour at position: ",gradientColour.position,"% with RGB: ",[gradientColour.r,gradientColour.g,gradientColour.b])
#Colour at position: 0.0 % with RGB: [255.0, 0.0, 0.0]
#Colour at position: 25.0 % with RGB: [0.0, 255.0, 255.0]
#Colour at position: 50.0 % with RGB: [255.0, 0.0, 255.0]
#Colour at position: 75.0 % with RGB: [255.0, 255.0, 0.0]
#Colour at position: 100.0 % with RGB: [0.0, 0.0, 0.0]

◆ clear()

void OMC::PaletteColour::clear ( )

Clear all colours from the object. Throws error if unsuccessful.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_solid_colour = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
#Size before:
print(new_solid_colour.size() == 2) # True, accounting for the colour at 0% and 100%.
# Clear colours:
new_solid_colour.clear()
#Size after:
print(new_solid_colour.size() == 2) # True
print(new_solid_colour.colour.r == 0) # True, the colour became default black.
# Create new colour inside palette and add colours:
new_gradient_colour = new_colour_palette.create_linear_gradient_colour('Colour_B',[255,0,0])
new_gradient_colour.add([0,255,255],25)
new_gradient_colour.add([255,0,255],50)
new_gradient_colour.add([255,0,255],75)
#Size before:
print(new_gradient_colour.size() == 5) # True
# Clear colours:
new_gradient_colour.clear()
#Size after:
print(new_gradient_colour.size() == 2) # True, accounting for the colour at 0% and 100%.

◆ contains()

bool OMC::PaletteColour::contains ( OMC::Colour  colour)

Identifies if the list contains the given colour. Item can be a 3 RGB or 4 RGBA array, a OMC::Color or a OMC::PaletteGradientPosition.

Returns
Return true if contains, and false otherwise.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_colour = new_colour_palette.create_linear_gradient_colour('Colour_A',[255,0,0])
# Add colours:
colour_position = new_colour.add([255,0,255],50) #initialized wiht alpha = 255
# Test contains colours:
print(new_colour.contains(colour_position)) # True
print(new_colour.contains([255,0,0])) # True
print(new_colour.contains([255,0,255,255])) # True

◆ interpolate()

OMC::PaletteGradientPosition OMC::PaletteColour::interpolate ( float  percentage)

Returns a gradient position at the interpolated position.

Returns
Returns a PaletteGradientPosition object at position.

Examplified at PaletteColour class description.

◆ list()

Array [OMC::PaletteGradientPosition] OMC::PaletteColour::list ( )

Converts the dynamic list into a concrete list of palette gradient position objects.

Returns
Returns an array of PaletteGradientPosition objects.

Examplified at PaletteColour class description.

◆ palette()

OMC::Palette* OMC::PaletteBaseColour::palette ( )
inherited

Gets the parent palette, or throws error if currently parentless.

Returns
The palette object.

Examplified in palette_list().

◆ palette_list()

OMC::PaletteList* OMC::PaletteBaseColour::palette_list ( )
inherited

Gets the parent palette list, or throws error if currently parentless.

Returns
The palette list object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_colour = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
# Access palette colours:
print(new_colour.palette_list().id == palette_list.id ) # True
print(new_colour.palette().id == new_colour_palette.id ) # True

◆ pop()

OMC::PaletteGradientPosition OMC::PaletteColour::pop ( int  index)

Pops given index object from this Palette colours.

Returns
The copy of the internally removed color gradient object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_colour = new_colour_palette.create_linear_gradient_colour('Colour_A',[255,0,0])
# Add colours:
new_colour.add([0,255,255],25)
new_colour.add([255,0,255],50)
new_colour.add([255,255,0],75)
# Pop at index:
new_colour.pop(2)
# List the colors on the gradient:
for gradientColour in new_colour:
print("Colour at position: ",gradientColour.position,"% with RGB: ",[gradientColour.r,gradientColour.g,gradientColour.b])
#Colour at position: 0.0 % with RGB: [255.0, 0.0, 0.0]
#Colour at position: 25.0 % with RGB: [0.0, 255.0, 255.0]
#Colour at position: 75.0 % with RGB: [255.0, 255.0, 0.0]
#Colour at position: 100.0 % with RGB: [0.0, 0.0, 0.0]

◆ remove()

void OMC::PaletteColour::remove ( OMC::PaletteGradientPosition  gradientPosition)

Remove a colour position from the gradient. Throws error if unsuccessful.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_colour = new_colour_palette.create_linear_gradient_colour('Colour_A',[255,0,0])
# Add colours:
new_colour.add([0,255,255],25)
colour_to_remove = new_colour.add([255,0,255],50)
new_colour.add([255,0,255],75)
# Remove colour:
new_colour.remove(colour_to_remove.colour) # Will remove all of the colours with the same value, in this case 50% and 75%.
# List the colors on the gradient:
for gradientColour in new_colour:
print("Colour at position: ",gradientColour.position,"% with RGB: ",[gradientColour.r,gradientColour.g,gradientColour.b])
#Colour at position: 0.0 % with RGB: [255.0, 0.0, 0.0]
#Colour at position: 25.0 % with RGB: [0.0, 255.0, 255.0]
#Colour at position: 100.0 % with RGB: [0.0, 0.0, 0.0]

Member Data Documentation

◆ a

float OMC::PaletteColour::a
readwrite

Get and set the alpha value of the colour 0-255.

◆ b

float OMC::PaletteColour::b
readwrite

Get and set the blue value of the colour 0-255.

◆ base_type

QString OMC::PaletteBaseColour::base_type
readinherited

The base type of colour, either 'Colour' or 'Texture'.

◆ colour

OMC::PaletteColour::colour

Get and set the colour object part of the gradient position.

◆ g

float OMC::PaletteColour::g
readwrite

Get and set the green value of the colour 0-255.

◆ h

double OMC::PaletteColour::h
readwrite

Get and set the hue value of the colour 0-360.

◆ hex

QString OMC::PaletteColour::hex
readwrite

Get and set the hex value of the colour in form #AARRGGBB.

◆ id

QString OMC::PaletteBaseColour::id
readinherited

Unique ID of the color.

◆ l

double OMC::PaletteColour::l
readwrite

Get and set the lightness value of the colour 0-100.

◆ name

QString OMC::PaletteBaseColour::name
readwriteinherited

The color pot name.

◆ operator[int index]

OMC::PaletteGradientPosition OMC::PaletteColour::operator[int index]

Provides the PaletteGradientPosition object at the given index. Note: setting value-type properties on the returned object will not take effect on this container object, since they are a copy and not the original object.

Returns
The palette gradient position object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create a new solid red palette colour:
new_colour = new_colour_palette.create_solid_colour('Red_Colour',[255,0,0,255])
colour_at_0 = new_colour[0].colour # copy to internal OMC::Colour object
print(new_colour[0].r == colour_at_0.r and \
new_colour[0].g == colour_at_0.g and \
new_colour[0].b == colour_at_0.b and \
new_colour[0].a == colour_at_0.a) # True
colour_at_0.r = 125 # set value on copy
print(new_colour[0].r != colour_at_0.r) # values on copy don't affect the original
# The color at index 0 is the color at position 0%
print(new_colour[0].r == 255 and \
new_colour[0].g == 0 and \
new_colour[0].b == 0 and \
new_colour[0].a == 255) # True
# The color at index 1 is the color at position 100%
print(new_colour[1].r == 255 and \
new_colour[1].g == 0 and \
new_colour[1].b == 0 and \
new_colour[1].a == 255) # True
new_colour.type = 'Linear' #change the type
new_colour.add([255,0,255],50) #adding a colour a 50% will change the values on the indexes
# The color at index 1 is the color at position 50%
print(new_colour[1].r == 255 and \
new_colour[1].g == 0 and \
new_colour[1].b == 255 and \
new_colour[1].a == 255) # True
# The color at index 1 is the color at position 100%
print(new_colour[2].r == 255 and \
new_colour[2].g == 0 and \
new_colour[2].b == 0 and \
new_colour[2].a == 255) # True

◆ r

float OMC::PaletteColour::r
readwrite

Get and set the red value of the colour 0-255.

◆ s

double OMC::PaletteColour::s
readwrite

Get and set the saturation value of the colour 0-100.

◆ type

QString OMC::PaletteColour::type
readwrite

Provides the type of PaletteGradientPosition, can be either Solid, Linear or Radial Gradient.

◆ valid

bool OMC::PaletteBaseColour::valid
readinherited

Get the validity of the object at the moment.

Inheritance diagram for OMC::PaletteColour:
Collaboration diagram for OMC::PaletteColour: