I wrote a program that shows primary, secondary and tertiary colors using classes.
#!/usr/bin/env python3
class ColorTypes:
def __init__(self, color, prisec='primary', primaryone='Red', primarytwo='None', secondaryone='None',
secondarytwo='None', complimentary ='None', output='This is a primary color'):
self.color = color
self.prisec = prisec
self.primaryone = primaryone
self.primarytwo = primarytwo
self.secondaryone = secondaryone
self.secondarytwo = secondarytwo
self.complimentary = complimentary
self.output = output
def red(self):
self.color = 'red'
self.prisec = 'primary'
self.primaryone = 'None'
self.primarytwo = 'None'
self.secondaryone = 'None'
self.secondarytwo = 'None'
self.complimentary = 'green'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'Tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def blue(self):
self.color = 'blue'
self.prisec = 'primary'
self.primaryone = 'None'
self.primarytwo = 'None'
self.secondaryone = 'None'
self.secondarytwo = 'None'
self.complimentary = 'orange'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'Tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def yellow(self):
self.color = 'yellow'
self.prisec = 'primary'
self.primaryone = 'None'
self.primarytwo = 'None'
self.secondaryone = 'None'
self.secondarytwo = 'None'
self.complimentary = 'purple'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'Tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def orange(self):
self.color = 'orange'
self.prisec = 'secondary'
self.primaryone = 'red'
self.primarytwo = 'yellow'
self.secondaryone = 'None'
self.secondarytwo = 'None'
self.complimentary = 'blue'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'Tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def green(self):
self.color = 'green'
self.prisec = 'secondary'
self.primaryone = 'blue'
self.primarytwo = 'yellow'
self.secondaryone = 'None'
self.secondarytwo = 'None'
self.complimentary = 'red'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'Tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def purple(self):
self.color = 'purple'
self.prisec = 'secondary'
self.primaryone = 'blue'
self.primarytwo = 'red'
self.secondaryone = 'None'
self.secondarytwo = 'None'
self.complimentary = 'yellow'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'Tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def redpurple(self):
self.color = 'red purple'
self.prisec = 'tertiary'
self.primaryone = 'red'
self.primarytwo = 'None'
self.secondaryone = 'purple'
self.secondarytwo = 'None'
self.complimentary = 'yellow green'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def orangered(self):
self.color = 'orange red'
self.prisec = 'tertiary'
self.primaryone = 'red'
self.primarytwo = 'None'
self.secondaryone = 'orange'
self.secondarytwo = 'None'
self.complimentary = 'blue green'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def orangeyellow(self):
self.color = 'orange yellow'
self.prisec = 'tertiary'
self.primaryone = 'yellow'
self.primarytwo = 'None'
self.secondaryone = 'orange'
self.secondarytwo = 'None'
self.complimentary = 'blue purple'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'tertiary':
print(self.secondaryone, 'and', self.primaryone, 'makes', self.color)
print('')
def yellowgreen(self):
self.color = 'yellow green'
self.prisec = 'tertiary'
self.primaryone = 'yellow'
self.primarytwo = 'None'
self.secondaryone = 'green'
self.secondarytwo = 'None'
self.complimentary = 'red purple'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'tertiary':
print(self.primaryone, 'and', self.secondaryone, 'makes', self.color)
print('')
def bluegreen(self):
self.color = 'blue green'
self.prisec = 'tertiary'
self.primaryone = 'blue'
self.primarytwo = 'None'
self.secondaryone = 'green'
self.secondarytwo = 'None'
self.complimentary = 'orange red'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'tertiary':
print(self.primaryone, 'and', self.secondaryone, 'makes', self.color)
print('')
def bluepurple(self):
self.color = 'blue purple'
self.prisec = 'tertiary'
self.primaryone = 'blue'
self.primarytwo = 'None'
self.secondaryone = 'purple'
self.secondarytwo = 'None'
self.complimentary = 'orange yellow'
print('This is the color', self.color)
print(self.color, 'is a', self.prisec, 'color', 'and its complimentary color is', self.complimentary)
if self.prisec == 'primary':
print('Primary colors cannot be mixed from other colors')
if self.prisec == 'secondary':
print(self.primaryone, 'and', self.primarytwo, 'makes', self.color)
if self.prisec == 'tertiary':
print(self.primaryone, 'and', self.secondaryone, 'makes', self.color)
print('')
class ColorTypesPick(ColorTypes):
pass
def main():
listcolors = ["Red", "Blue", "Yellow", "Orange", "Green", "Purple", "Red-purple", "Orange-red", "Orange-yellow",
"Yellow-green", "Blue-green", "Blue-purple"]
lengthlist = len(listcolors)
count = 0
while count < lengthlist:
x = listcolors[count]
thiscolor = ColorTypesPick(',x,')
if x == 'Red':
thiscolor.red()
count += 1
if x == 'Blue':
thiscolor.blue()
count += 1
if x == 'Yellow':
thiscolor.yellow()
count += 1
if x == 'Orange':
thiscolor.orange()
count += 1
if x == 'Green':
thiscolor.green()
count += 1
if x == 'Purple':
thiscolor.purple()
count += 1
if x == 'Red-purple':
thiscolor.redpurple()
count += 1
if x == 'Orange-red':
thiscolor.orangered()
count += 1
if x == 'Orange-yellow':
thiscolor.orangeyellow()
count += 1
if x == 'Yellow-green':
thiscolor.yellowgreen()
count += 1
if x == 'Blue-green':
thiscolor.bluegreen()
count += 1
if x == 'Blue-purple':
thiscolor.bluepurple()
count += 1
if __name__ == "__main__":
main()
The output:
/home/michael/PycharmProjects/colors.py/venv/bin/python /home/michael/PycharmProjects/colors.py/ColorTypes.py
This is the color red
red is a primary color and its complimentary color is green
Primary colors cannot be mixed from other colors
This is the color blue
blue is a primary color and its complimentary color is orange
Primary colors cannot be mixed from other colors
This is the color yellow
yellow is a primary color and its complimentary color is purple
Primary colors cannot be mixed from other colors
This is the color orange
orange is a secondary color and its complimentary color is blue
red and yellow makes orange
This is the color green
green is a secondary color and its complimentary color is red
blue and yellow makes green
This is the color purple
purple is a secondary color and its complimentary color is yellow
blue and red makes purple
This is the color red purple
red purple is a tertiary color and its complimentary color is yellow green
purple and red makes red purple
This is the color orange red
orange red is a tertiary color and its complimentary color is blue green
orange and red makes orange red
This is the color orange yellow
orange yellow is a tertiary color and its complimentary color is blue purple
orange and yellow makes orange yellow
This is the color yellow green
yellow green is a tertiary color and its complimentary color is red purple
yellow and green makes yellow green
This is the color blue green
blue green is a tertiary color and its complimentary color is orange red
blue and green makes blue green
This is the color blue purple
blue purple is a tertiary color and its complimentary color is orange yellow
blue and purple makes blue purple
Process finished with exit code 0