importargparsefromcolorsysimporthls_to_rgb,rgb_to_hlsimportsys# setting up argumentsparser=argparse.ArgumentParser(description='Function that outputs a pleasant text color hex ''given a background color hex')parser.add_argument('color',help='Color in #xxxxxx or xxxxxx format')args=parser.parse_args()color=args.color# removing #ifcolor.startswith('#'):color=color[1:]# splitting, converting to decimal and then to 0-1 rangetry:r,g,b=[int(color[i:i+2],16)/255.0foriinrange(0,len(color),2)]exceptValueError:print'Wrong color supplied'sys.exit()# shiftingh,l,s=[(i+0.5)%1foriinrgb_to_hls(r,g,b)]# converting back to rgbresult=[format(int(i*255),'x')foriinhls_to_rgb(h,l,s)]print'#{}'.format(''.join(result))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I implemented this in python: