Get the App
SLTechnology News&Howtos  ›  Development  › 

The conversion between hexadecimal and RGB color values and how to judge a prime and inline function and object-oriented

Shulou Source: shulou.com Published: 2022-06-03 05:56:14 09月21日 Update

Today, I will talk to you about the conversion between hexadecimal and RGB color values and how to judge a prime number and inline function and object-oriented. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents. I hope you can get something from this article.

Conversion between hexadecimal and RGB color values

/ * *

* randomly generate colors

* @ return randomly generated hexadecimal colors

, /

Function randomColor () {

Var colorStr=Math.floor (Math.random () * 0xFFFFFF) .toString (16) .toUpperCase ()

Return "#" + "000000" .substring (0mai 6m color Str) + colorStr

}

/ * *

* convert hexadecimal colors to RGB colors

* @ param color the hexadecimal color to convert

* @ return RGB Color

, /

Function colorHexToRGB (color) {

Color=color.toUpperCase ()

Var regexpHex=/ ^ # [0-9a-fA-F] {3jie 6} $/; / Hex

If (regexpHex.test (color)) {

Var hexArray=new Array ()

Var count=1

For (var iharma i3muri) {

HexArray.push (Number ("0x" + color.substring (count,count+2)

Count+=2

} else {

HexArray.push (Number ("0x" + color.charAt (count) + color.charAt (count)

Count+=1

}

}

Return "RGB (" + hexArray.join (",") + ")"

} else {

Return color

}

}

/ * *

* convert RGB colors to hexadecimal colors

* @ param color the RGB color to convert

* @ return hex color

, /

Function colorRGBToHex (color) {

Var regexpRGB=/ ^ (rgb | RGB)\ ([0-9] {1pr 3},\ s? [0-9] {1jue 3},\ s? [0-9] {1pr 3}\) $/; / / RGB

If (regexpRGB.test (color)) {

Color=color.replace (/ (\ (|\) | rgb | RGB) * / g, ") .split (", ")

Var colorHex= "#"

For (var iTuno Bandi)

Tags: Functions colors hexadecimal primes members objects content compilers compilers normal code keywords just combined numbers overhead efficiency data speed C++ Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi macOS Huawei OPPO Reno