CSc 120: Classes: Color
Expected Behavior
The class Color represents a color using the RGB color model. (See the following reference for information on the RGB color model:
https://en.wikipedia.org/wiki/RGB_color_model .)
The class Color stores the red, green, and blue components of a color as integers.
Each integer is in the range of range of 0 to 255 (inclusive).
Write a Python class Color that meets the following requirements:
Attributes:
-
_r: an integer in the range of 0 to 255 (inclusive)
-
_g: an integer in the range of 0 to 255 (inclusive)
-
_b: an integer in the range of 0 to 255 (inclusive)
Methods:
Examples
-
color1 = Color(50,100,140)
color1.get_rgb()
Result: (50, 100, 140)
-
color1 = Color(50,100,140)
str(color1)
Result: "Color(50,100,140)"
-
color1 = Color(135,50,140)
color1.remove_red()
str(color1)
Result: "Color(0,50,140)"
-
color1 = Color(50,100,140)
color2 = Color(135,50,140)
color1 == color2
Result: False
-
color1 = Color(65,100,180)
color2 = Color(65,100,180)
color1 == color2
Result: True
-
color1 = Color(255,255,255)
color1.remove_red()
str(color1)
Result: "Color(0,255,255)"
-
color1 = Color(255,255,255)
color1.remove_red()
color1.get_rgb()
Result: (0,255,255)
-
color1 = Color(50,100,140)
color1.get_rgb()[2]
Result: 140