瀏覽代碼

Color sub (#9134)

* add Color.sub()

* add tab

* if result is negative set to 0

* revise doc of color.sub()
Zhongrui Li 9 年之前
父節點
當前提交
77637ae9c4
共有 2 個文件被更改,包括 15 次插入0 次删除
  1. 5 0
      docs/api/math/Color.html
  2. 10 0
      src/math/Color.js

+ 5 - 0
docs/api/math/Color.html

@@ -185,6 +185,11 @@
 		Adds given h, s, and l to this color's existing h, s, and l values.
 		</div>
 
+		<h3>[method:Color sub]( [page:Color color] ) [page:Color this]</h3>
+		<div>
+		Subtracts rgb components of given color from rgb components of this color. If a component is negative, it is set to zero.
+		</div>
+
 		<h3>[method:Color add]( [page:Color color] ) [page:Color this]</h3>
 		<div>
 		Adds rgb values of given color to rgb values of this color

+ 10 - 0
src/math/Color.js

@@ -381,6 +381,16 @@ THREE.Color.prototype = {
 
 	},
 
+	sub: function( color ) {
+
+		this.r = Math.max( 0, this.r - color.r );
+		this.g = Math.max( 0, this.g - color.g );
+		this.b = Math.max( 0, this.b - color.b );
+
+		return this;
+
+	},
+
 	add: function ( color ) {
 
 		this.r += color.r;