def convert_tuple_to_hex(rgb, raw=False):
	"""
	Converts an RGB color tuple info a hex string such as #ff0000. If *raw* is
	True then each value is treated as if it were on a scale from 0 to 255
	instead of 0.0 to 1.0.

	:param tuple rgb: The RGB tuple to convert into a string.
	:param bool raw: Whether the values are raw or percentages.
	:return: The RGB color as a string.
	:rtype: str
	"""
	if raw:
		rgb = (int(x) for x in rgb)
	else:
		rgb = (int(round(float(x) * 255.0)) for x in rgb)
	return "#{0:02x}{1:02x}{2:02x}".format(*rgb)