# RGBA指定の16進⇔10進の変換

# rgba(r, g, b, a) → #1f1f1f1f

#!/usr/bin/env python3

import sys

color = '#'

for x in sys.argv[1:4]:
  color += '%02x' % int(x)

for x in sys.argv[4:5]:
  color += '%02x' % int(float(x) * 255)


print(color)

# #1f1f1f1f → rgba(r, g, b, a)

#!/usr/bin/env python3

import re
import sys

rgba_h = re.findall('(..)', sys.argv[1].replace('#', ''))

print(rgba_h)
rgba_d = []

for x in rgba_h[0:3]:
  rgba_d.append(int(x, 16))

for x in rgba_h[3:4]:
  rgba_d.append(float(x, 16) / 255)


print(rgba_d)

[ 📩 ご意見 ]