aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/colorconvert
blob: 6777f2338d10e057364364e8286cfb7a17f110f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3

import sys
import colorsys

def hsl2hex(color):
  # regex = r'hsl\(\s*(\d+),\s*(\d+)%,\s*(\d+)%\s*\);'
  # lines = [re.findall(regex,line) for line in one_dark_syn.split('\n')]
  # rgbs = [colorsys.hsv_to_rgb(int(line[1][0])/360, int(line[0][1])/100, int(line[0][2])/100) for line in lines if line]
  # rgbhex = ["".join("%03X" % round(i*255) for i in rgb) for rgb in rgbs]

  colors = color.split(",")
  color_rgb_frac = colorsys.hls_to_rgb(int(colors[0]) / 360, int(colors[2]) / 100, int(color[1]) / 100)
  print(color_rgb_frac)
  color_rgb = [round(value / 255) for value in color_rgb_frac]
  print(color_rgb)
  color_hex = [",".join("%3X" % rgb for rgb in color_rgb)]
  print(color_hex)
  return color_hex

# https://www.rapidtables.com/convert/color/hsl-to-rgb.html

if __name__ == "__main__":
  if sys.argv[1] == "hsl2hex":
    print(hsl2hex(sys.argv[2]))
  else:
    print("Usage example:\ncolorconvert hsl2hex 78,50,60")