+def _add(colour, amount):
+ """
+ Adds some value to colours
+ """
+ # Parse hex array
+ bytes = bytearray.fromhex(colour.lstrip("#"))
+
+ if not len(bytes) == 3:
+ raise ValueError("Invalid colour: %s" % colour)
+
+ ret = bytearray()
+
+ for byte in bytes:
+ byte = round(byte * amount)
+
+ # Ensure the result is within range
+ byte = min(byte, 255)
+ byte = max(byte, 0)
+
+ # Update the array
+ ret.append(byte)
+
+ return "#%s" % ret.hex()
+
+def lighten(colour, scale=0.1):
+ """
+ Takes a hexadecimal colour code
+ and brightens the colour.
+ """
+ return _add(colour, scale)
+
+def darken(colour, scale=0.1):
+ """
+ Takes a hexadecimal colour code
+ and darkens the colour.
+ """
+ return _add(colour, -scale)
+
+def transparency(colour, scale=0.1):
+ """
+ Adds transparency to the given colour code
+ """
+ return "%s%02X" % (colour, 0xff * scale)