Skip to content

@lrvick /rgbint.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Go from rgb to 32bit int or vice-versa
#!/bin/python
import random
def rgb_to_int(r,g,b):
i = str()
for c in r,g,b:
for d in str("%03d" % (c,)):
i += '%s%s%s' % (d,d,d)
return i
def int_to_rgb(integer):
rgb = []
ri = integer[:9]
gi = integer[9:18]
bi = integer[18:32]
for i in [ri,gi,bi]:
c = i[:1]
c += i[3:4]
c += i[7:8]
rgb.append(c)
return rgb
r = random.randrange(1,255)
g = random.randrange(1,255)
b = random.randrange(1,255)
integer = rgb_to_int(r,g,b)
print "integer = %s" % rgb_to_int(r,g,b)
print "rgb = %s" % int_to_rgb(integer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.