Colors

class RGBColorCell(r=None, b=None, g=None)[source]

A Cell representation of an RGB Color.

Parameters:r,b,g (int) – Integers in the range 0 to 255 inclusive
classmethod from_name(clz, name)[source]

Instantiates the object from a known color name. The list of known names, along with their RGB values:

red: [255,0,0]
cyan: [0,255,255]
blue: [0, 0, 255]
medium_blue: [0, 0, 205]
black: [0,0,0]
white: [255,255,255]
green: [0,128,0]
light_blue: [30, 144,255]
teal: [0, 128, 128]
yellow: [255, 255,0]
Parameters:name (str) – Color to use for the RGBColorCell
Returns:RGBColorCell
to_html()[source]

Converts to Hex

Returns:str
>>> b = RGBColorCell.from_name('black')
>>> w = RGBColorCell.from_name('white')
>>> t = RGBColorCell.from_name('teal')
>>> b.to_html()
'#000000'
>>> w.to_html()
'#ffffff'
>>> t.to_html()
'#008080'
classmethod coerce(clz, other)[source]

Raises an Exception if other is not an instance of RGBColorCell.

Parameters:other (RGBColorCell) – An instance of RGBColorCell
Returns:RGBColorCell
Raises:Exception
membership_score(element)[source]

Fuzzy set gradable membership score.

See http://code.google.com/p/python-colormath/wiki/ColorDifferences

Parameters:element (RGBColorCell) – A Color Cell
Returns:float - In the range of 0 to 1
Raises:Exception
>>> colorCell1 = RGBColorCell(0,150,255)
>>> colorCell2 = RGBColorCell(100,30,75)
>>> colorCell1.membership_score(colorCell2)
0.7719099090792914
>>> colorCell1.membership_score(colorCell1)
1.0
merge(other)[source]

Merges the values

Parameters:other (RGBColorCell) – an RGBColorCell to merge with
Returns:RGBColorCell
Raises:Exception, Contradiction
is_contradictory(other)[source]

Two Color Cells are contradictory if their membership_score is not equal to 1.0

Parameters:other (RGBColorCell) – A Color Cell to compare
Returns:bool
Raises:Exception
>>> b = RGBColorCell.from_name('black')
>>> w = RGBColorCell.from_name('white')
>>> b.membership_score(w)
0.0215265678169
>>> b.is_contradictory(w)
True
>>> b.membership_score(b)
1.0
>>> b.is_contradictory(b)
False
is_equal(other)[source]

Returns True if the distance, i.e. membership_score, is 0

Parameters:other – RGBColorCell
Returns:bool
Raises:Exception if other is not an instance of RGBColorCell
>>> b = RGBColorCell.from_name('black')
>>> w = RGBColorCell.from_name('white')
>>> b.membership_score(b)
1.0
>>> b.is_equal(b)
True
>>> b.membership_score(w)
0.0215265678169
>>> b.is_equal(w)
False

Previous topic

Bools

Next topic

Dicts

This Page