A fairly classic way to set colours in a computer program consists of splitting the colour in three components: red, green and blue. Each of these components is an integer and takes a value betwee 0 and 255 (boundaries included). Within this system, the greyscales correspond to the colours in which the three components have the same value.

If a photo must be printed as a greyscale picture, every colour must be converted to a specific greyscale. You could use the mean value, for example, but this gives a wrong image, since the human eye is not equally sensitive to every colour. This is why the following conversion is often used:

greyscale = 30% of red + 59% of green + 11% of blue

If a picture should be made unrecognizable, one sometimes inverts parts of the picture. Here, every colour is replaced by its inverse colour. In order to obtain this colour, you should replace every component by 255 minus that component. 

Assignment

Your assignment consists of making a class Colour with the following methods:

  1. The initializing method __init__ gets the three colour components as parameters, where each component gets the value 0 as a standard. Make sure that only components between 0 and 255 are used: values smaller than 0 are replaced with 0, values larger than 255 are replaced with 255.

  2. The method __str__ represents this colour as a string in the format (R, G, B), where R, G and B indicate the different components.

  3. The method inverse prints a new Colour that represents the inverse colour.

  4. The method greyscale prints a new Colour that represents the greyscale of this colour according to the calculation above. 

Example

>>> c = Colour(128, 62, -50)
>>> print(k)
(128, 62, 0)
>>> c = Colour(128, 62, 350)
>>> c
(128, 62, 255)
>>> g = c.greyscale()
>>> g
(103, 103, 103)
>>> i = c.inverse()
>>> i
(127, 193, 0)
>>> i.greyscale()
(151, 151, 151)