RBG to Hex conversion now working

This commit is contained in:
2024-11-29 20:51:55 -05:00
parent 49364eb1d2
commit 1151562d73
+16 -7
View File
@@ -11,11 +11,10 @@ def main():
parser.add_argument('color', nargs='*', help='accepts a color in Hex, RGB, CYMK, or HSL and performs format conversions')
args = parser.parse_args()
print('TYPES: ', TYPES)
print(args)
print(args, '\n')
color = args.color
if len(color) == 0 :
print('ERROR: Must enter color code')
return
@@ -47,7 +46,6 @@ def main():
# Takes in valid RGB code and converts it to the other formats
def convertFromHex(hexCode) :
print('-> Hex received: ', hexCode, ' ', type(hexCode))
convertToRGB('hex', hexCode)
# convertToCMYK('hex', code)
# convertToHSL('hex', code)
@@ -69,15 +67,25 @@ def convertToHex(codeFormat, code) :
# Takes in valid RGB code and converts it to the other formats
def convertFromRGB(code) :
print('-> RGB received: ', code, ' ', type(code[0]), type(code[1]), type(code[2]))
convertToHex('rgb', code)
# convertToCMYK('rgb', code)
# convertToHSL('rgb', code)
def convertToRGB(codeFormat, code) :
if codeFormat == 'hex' :
print('bsdfljbsdfb')
rgbValue = ''
if codeFormat == 'hex' :
tempSum = 0
i = 0
while i < 6 :
tempSum += int(code[i], 16) * 16
tempSum += int(code[i+1], 16)
rgbValue += str(tempSum) + ' '
i = i + 2
tempSum = 0
print('RGB: ', rgbValue)
##
# INPUT VALIDATION SECTION
##
@@ -127,5 +135,6 @@ def hex(number) :
return HEX_LETTERS[number % 10]
if __name__ == '__main__' :
main()