converting to CMYK now working

This commit is contained in:
2024-11-30 20:09:36 -05:00
parent b96470c1b5
commit 9884055333
+53 -19
View File
@@ -62,6 +62,7 @@ def main():
return return
print('convert cmyk: ', color) print('convert cmyk: ', color)
convertFromCMYK(color)
## ##
# HEX CONVERSION SECTION # HEX CONVERSION SECTION
## ##
@@ -69,19 +70,23 @@ 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('convert hex: ', hexCode) print('convert hex: ', hexCode)
convertToRGB('hex', hexCode)
# convertToCMYK('hex', code) rgbValues = hexToRGB(hexCode)
print("RGB: ", rgbValues)
cmykValues = rgbToCMYK(rgbValues)
print("CMYK: ", cmykValues)
# convertToHSL('hex', code) # convertToHSL('hex', code)
def convertToHex(codeFormat, code) : def rgbToHex(rgbValues) :
hexValue = '#' hexValue = ''
if codeFormat == 'rgb' : for rgbValue in rgbValues :
for rgbValue in code :
hexValue += hex(int(rgbValue / 16)) hexValue += hex(int(rgbValue / 16))
hexValue += hex(int(rgbValue % 16)) hexValue += hex(int(rgbValue % 16))
print('HEX: ', hexValue) return hexValue
## ##
@@ -89,29 +94,58 @@ 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(rgbValues) :
print('convert RGB: ', code) print('convert RGB: ', rgbValues)
convertToHex('rgb', code)
# convertToCMYK('rgb', code)
# convertToHSL('rgb', code)
def convertToRGB(codeFormat, code) : hexCode = rgbToHex(rgbValues)
rgbValue = '' print('Hex: ', hexCode)
if codeFormat == 'hex' : cmykValues = rgbToCMYK(rgbValues)
print('CMYK: ', cmykValues)
# convertToHSL('rgb', rgbValues)
def hexToRGB(hexCode) :
rgbValues = []
tempSum = 0 tempSum = 0
i = 0 i = 0
while i < 6 : while i < 6 :
tempSum += int(code[i], 16) * 16 tempSum += int(hexCode[i], 16) * 16
tempSum += int(code[i+1], 16) tempSum += int(hexCode[i+1], 16)
rgbValue += str(tempSum) + ' ' rgbValues.append(tempSum)
i = i + 2 i = i + 2
tempSum = 0 tempSum = 0
print('RGB: ', rgbValue) return rgbValues
##
# CMYK CONVERSION SECTION
##
def convertFromCMYK() :
print('huh')
def rgbToCMYK(rgbValues) :
# Normalize RGB values
normalRed = rgbValues[0] / 255
normalGreen = rgbValues[1] / 255
normalBlue = rgbValues[2] / 255
# Establish black
black = 1 - max(normalRed, normalGreen, normalBlue)
x = 1 - black
# Convert
cyan = (1 - normalRed - black) / x
magenta = (1 - normalGreen - black) / x
yellow = (1 - normalBlue - black) / x
return [cyan, magenta, yellow, black]
def cmykToRGB(cmykValues) :
print('ddf')
## ##
# INPUT VALIDATION SECTION # INPUT VALIDATION SECTION