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
print('convert cmyk: ', color)
convertFromCMYK(color)
##
# HEX CONVERSION SECTION
##
@@ -69,19 +70,23 @@ def main():
# Takes in valid RGB code and converts it to the other formats
def convertFromHex(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)
def convertToHex(codeFormat, code) :
hexValue = '#'
def rgbToHex(rgbValues) :
hexValue = ''
if codeFormat == 'rgb' :
for rgbValue in code :
for rgbValue in rgbValues :
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
def convertFromRGB(code) :
print('convert RGB: ', code)
convertToHex('rgb', code)
# convertToCMYK('rgb', code)
# convertToHSL('rgb', code)
def convertFromRGB(rgbValues) :
print('convert RGB: ', rgbValues)
def convertToRGB(codeFormat, code) :
rgbValue = ''
hexCode = rgbToHex(rgbValues)
print('Hex: ', hexCode)
if codeFormat == 'hex' :
cmykValues = rgbToCMYK(rgbValues)
print('CMYK: ', cmykValues)
# convertToHSL('rgb', rgbValues)
def hexToRGB(hexCode) :
rgbValues = []
tempSum = 0
i = 0
while i < 6 :
tempSum += int(code[i], 16) * 16
tempSum += int(code[i+1], 16)
rgbValue += str(tempSum) + ' '
tempSum += int(hexCode[i], 16) * 16
tempSum += int(hexCode[i+1], 16)
rgbValues.append(tempSum)
i = i + 2
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