I've been learning three.js recently, and I'm a little confused about the color settings, so I decided to study it.
First let’s look at two methods of setting color:
- To set a color for objects in webgl and three.js, use
color: 0x00ff00
- To set a color in css, you can use
color: #00ff00
orrgba(0, 255, 0, 1)
What is the difference between the above three methods?
rgba(0, 255, 0, 1)
It is easy to understand, it is an RGB color value;#00ff00
rgba(0, 255, 0, 1)
: Frequently used in CSS, it is a relatively common hexadecimal representation of color. It can be converted to this representation in multiple tools such as browser debugging tools ;- What is more difficult to understand
0x00ff00
is that it is also a hexadecimal representation of color, but the#00ff00
difference is: replace#00ff00
the previous one#
with0x
(here is the key point, the key point!!!) .
So, do you understand? No need to worry about 0x00ff00
the representation of this color anymore. Use tools to get the #00ff00
representation of the color you want, then #
change it 0x
and use it in webgl and three.js.
Finally, regarding the color value conversion tool:
- Browser debugging tools
- Tool for novice tutorial: RGB to hexadecimal conversion
These two are enough. Happy learning everyone!