The Color.equals()
method is used to compare two THREE.Color
objects and returns true
if they are equal and false
otherwise.
color.equals(otherColor);
otherColor
: The THREE.Color
object to compare with.The method returns a Boolean
value: true
if the two colors are equal, false
otherwise.
const color1 = new THREE.Color(0xff0000);
const color2 = new THREE.Color("red");
const color3 = new THREE.Color(0x00ff00);
console.log(color1.equals(color2)); // returns true
console.log(color1.equals(color3)); // returns false
The Color.equals()
method compares the red, green, and blue components of the two colors, as well as the alpha component if it is present. If all components are equal, the method returns true
, otherwise, it returns false
.
When comparing THREE.Color
objects, it is recommended to use the equals()
method instead of the ==
operator, as the objects may have different reference values even if their RGB values are the same.
The Color.equals()
method is supported in all modern browsers.
THREE.Color
class in the three.js documentation.THREE.Color.getHexString()
method in the three.js documentation.