Advertisement
Guest User

ColorConvert

a guest
Aug 25th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import os
  2. import ctypes
  3.  
  4. # Code by OfficialMango
  5.  
  6. os.system('cls')
  7. ctypes.windll.kernel32.SetConsoleTitleA("ColorConvert by OfficialMango")
  8.  
  9. class Frontend():
  10. def menu(self):
  11. while(True):
  12. os.system('cls')
  13. message = '''
  14. Welcome to ColorConvert!
  15.  
  16. Type a number and hit ENTER!
  17.  
  18. 1. Convert HEX to FLOAT
  19. 2. Convert FLOAT to HEX
  20.  
  21. Note: If you ever wish to return here, simply type "menu"
  22.  
  23. '''
  24. usr_input = raw_input(message)
  25. if str(usr_input) == '1':
  26. os.system('cls')
  27. return True
  28. elif str(usr_input) == '2':
  29. os.system('cls')
  30. return False
  31.  
  32. class HexToFloat():
  33. def rgbconvert(self,_value):
  34. _value = float(_value) / float(255)
  35. return _value ** 2.2
  36.  
  37. def menu(self):
  38. while(True):
  39. h = raw_input('Enter hex: ').lstrip('#')
  40. if h == 'menu' or h == 'home':
  41. os.system('cls')
  42. Frontend.menu()
  43. else:
  44. os.system('cls')
  45. try:
  46. r, g, b = tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
  47. print('RGB =', r, g, b)
  48. print('Float Red =', self.rgbconvert(r))
  49. print('Float Green =', self.rgbconvert(g))
  50. print('Float Blue =', self.rgbconvert(b))
  51. except:
  52. print('Invalid input, maybe not a valid Hex color?')
  53.  
  54. class FloatToHex():
  55.  
  56. def checkInput(self,_input):
  57. if _input == 'menu' or _input == 'home':
  58. os.system('cls')
  59. Frontend.menu()
  60. else:
  61. pass
  62.  
  63. def castInput(self,_value):
  64. x = float(_value)**(1/2.2)
  65. y = float(x)*255
  66. return y
  67.  
  68. def menu(self):
  69. while(True):
  70. #Red
  71. float_red = raw_input('Insert red float value: ')
  72. self.checkInput(float_red)
  73. try:
  74. _red = self.castInput(float_red)
  75. except:
  76. print 'Invalid Input'
  77.  
  78. #Green
  79. float_green = raw_input('Insert green float value')
  80. self.checkInput(float_green)
  81. try:
  82. _green = self.castInput(float_green)
  83. except:
  84. print 'Invalid Input'
  85.  
  86. #Blue
  87. float_blue = raw_input('Insert blue float value')
  88. self.checkInput(float_blue)
  89. try:
  90. _blue = self.castInput(float_blue)
  91. except:
  92. print 'Invalid Input'
  93. print _red
  94. print _green
  95. print _blue
  96.  
  97. Frontend = Frontend()
  98. if Frontend.menu() == True:
  99. HexToFloat = HexToFloat()
  100. HexToFloat.menu()
  101. else:
  102. FloatToHex = FloatToHex()
  103. FloatToHex.menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement