HTML color and RGB color conversion

There are many ways to express colors. Generally, many colors have corresponding English letters, such as this effect, but it is really difficult to remember the English of each color. There are two other ways to express colors.Insert picture description here

  1. RGB colors
    As we all know, red, green, and blue are the three primary colors, corresponding to red, green, and blue respectively, which is what we often call RGB colors. Each color is composed of the three primary colors in a certain proportion. The proportions of the three primary colors are different, and the colors are of course different.

RGB colors use three numbers to represent the proportions of the three colors, also called three channels, and the value is an integer between 0 and 255.
For example, if a color is represented by RGB color (255,250,250), if you want to convert it into HTML color, each of the three numbers is converted into a corresponding hexadecimal number, which is a two-digit number, which will eventually become a 6-digit number. 255——FF, 250——FA, 250——FA, so the final result is #FFFAFA, the conversion is successful!

Then the process of converting HTML color into RGB color is just the opposite, which is the process of converting three hexadecimal numbers into decimal system~~

  • Convert RGB color to hexadecimal color
color=input()
number='#'
color1=color.split() 
#print(color1)
for i in color1:
    shu=hex(int(i))[2:]
    if len(shu)<2:
        shu='0'+shu
    number+=shu
print(number.upper())   
255 255 255
#FFFFFF
0 0 0
#000000
  • Convert HTML colors to RGB colors
color=input()
lis=[]
for i in range(0,6,2):
    lis.append(color[i:i+2])
for i in lis:
    i=int(eval('0x'+i))
    print(i,end=' ')
542a32
84 42 50
42bb33
66 187 51

Guess you like

Origin blog.csdn.net/weixin_46530492/article/details/108273109