summaryrefslogtreecommitdiff
path: root/color-converter.py
diff options
context:
space:
mode:
authorSimon <vesspa0330@gmail.com>2024-11-30 20:09:36 -0500
committerSimon <vesspa0330@gmail.com>2024-11-30 20:09:36 -0500
commit9884055333161c03d2ef331aeac1b15a21454cbf (patch)
tree78ace486bb7eff732e1aab7958d808f5848101b8 /color-converter.py
parentb96470c1b5269f4c09485bcf33a4722b875103f0 (diff)
converting to CMYK now working
Diffstat (limited to 'color-converter.py')
-rw-r--r--color-converter.py88
1 files changed, 61 insertions, 27 deletions
diff --git a/color-converter.py b/color-converter.py
index 80259aa..157dc89 100644
--- a/color-converter.py
+++ b/color-converter.py
@@ -60,8 +60,9 @@ def main():
color = color[0].lower().strip('cmyk(').strip(')').replace('%', '').replace(' ', '').split(',')
if not validateCMYK(color) :
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 :
- hexValue += hex(int(rgbValue / 16))
- hexValue += hex(int(rgbValue % 16))
+ for rgbValue in rgbValues :
+ hexValue += hex(int(rgbValue / 16))
+ hexValue += hex(int(rgbValue % 16))
- print('HEX: ', hexValue)
+ return hexValue
##
@@ -89,30 +94,59 @@ 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)
+
+ hexCode = rgbToHex(rgbValues)
+ print('Hex: ', hexCode)
-def convertToRGB(codeFormat, code) :
- rgbValue = ''
+ cmykValues = rgbToCMYK(rgbValues)
+ print('CMYK: ', cmykValues)
- if codeFormat == 'hex' :
-
+ # convertToHSL('rgb', rgbValues)
+
+def hexToRGB(hexCode) :
+ rgbValues = []
+
+ tempSum = 0
+ i = 0
+ while i < 6 :
+ tempSum += int(hexCode[i], 16) * 16
+ tempSum += int(hexCode[i+1], 16)
+ rgbValues.append(tempSum)
+ i = i + 2
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)
+ 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
##