RBG to Hex conversion now working

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