Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import ctypes
- # Code by OfficialMango
- os.system('cls')
- ctypes.windll.kernel32.SetConsoleTitleA("ColorConvert by OfficialMango")
- class Frontend():
- def menu(self):
- while(True):
- os.system('cls')
- message = '''
- Welcome to ColorConvert!
- Type a number and hit ENTER!
- 1. Convert HEX to FLOAT
- 2. Convert FLOAT to HEX
- Note: If you ever wish to return here, simply type "menu"
- '''
- usr_input = raw_input(message)
- if str(usr_input) == '1':
- os.system('cls')
- return True
- elif str(usr_input) == '2':
- os.system('cls')
- return False
- class HexToFloat():
- def rgbconvert(self,_value):
- _value = float(_value) / float(255)
- return _value ** 2.2
- def menu(self):
- while(True):
- h = raw_input('Enter hex: ').lstrip('#')
- if h == 'menu' or h == 'home':
- os.system('cls')
- Frontend.menu()
- else:
- os.system('cls')
- try:
- r, g, b = tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
- print('RGB =', r, g, b)
- print('Float Red =', self.rgbconvert(r))
- print('Float Green =', self.rgbconvert(g))
- print('Float Blue =', self.rgbconvert(b))
- except:
- print('Invalid input, maybe not a valid Hex color?')
- class FloatToHex():
- def checkInput(self,_input):
- if _input == 'menu' or _input == 'home':
- os.system('cls')
- Frontend.menu()
- else:
- pass
- def castInput(self,_value):
- x = float(_value)**(1/2.2)
- y = float(x)*255
- return y
- def menu(self):
- while(True):
- #Red
- float_red = raw_input('Insert red float value: ')
- self.checkInput(float_red)
- try:
- _red = self.castInput(float_red)
- except:
- print 'Invalid Input'
- #Green
- float_green = raw_input('Insert green float value')
- self.checkInput(float_green)
- try:
- _green = self.castInput(float_green)
- except:
- print 'Invalid Input'
- #Blue
- float_blue = raw_input('Insert blue float value')
- self.checkInput(float_blue)
- try:
- _blue = self.castInput(float_blue)
- except:
- print 'Invalid Input'
- print _red
- print _green
- print _blue
- Frontend = Frontend()
- if Frontend.menu() == True:
- HexToFloat = HexToFloat()
- HexToFloat.menu()
- else:
- FloatToHex = FloatToHex()
- FloatToHex.menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement