Difference between revisions of "Legacy:BlendColorsWeighted"

From Spherical
Jump to: navigation, search
(Usage: param types)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Functions]]
+
Returns a [[API:Color|Color]] object that is the blended color of the two input colors, (c1 and c2) but allows you to specify the amount of each color.
Returns a Color object that is the blended color of the two input colors, (c1 and c2) but allows you to specify the amount of each color.
 
  
 
==Usage==
 
==Usage==
 +
{{Usage|returns=[[API:Color|Color]]|func=BlendColorsWeighted|params=c1, c2, c1_weight, c2_weight}}
  
;[[Color]] BlendColorsWeighted(c1, c2, c1_weight, c2_weight);
+
* '''c1''' [[API:Color|Color]]. a color object created with [[API:CreateColor|CreateColor]]
 +
* '''c2''' [[API:Color|Color]]. a color object created with CreateColor
 +
* '''c1_weight''' integer. amount of first color
 +
* '''c2_weight''' integer. amount of second color
  
* '''c1''' a color object created with [[CreateColor]]
+
==Notes==
* '''c2''' a color object created with CreateColor
 
* '''c1_weight''' amount of first color
 
* '''c2_weight''' amount of second color
 
  
 
+
The weights of the two colors are converted to a ratio out of 100%. (1:2 means one part of the first to two parts of the second. Or 33% of the first to 66% of the second.)
NOTE:The weights of the two colors are converted to a ratio out of 100%. (1:2 means one part of the first to two parts of the second. Or 33% of the first to 66% of the second.)
 
  
 
==Examples==
 
==Examples==
Line 36: Line 35:
 
==See also==
 
==See also==
  
* Sphere [[Color]] object
+
* Sphere [[API:Color|Color]] object
* [[CreateColor]]()
+
* [[API:CreateColor|CreateColor]]()
* [[ApplyColorMask]]()
+
* [[API:ApplyColorMask|ApplyColorMask]]()
* [[BlendColors]]()
+
* [[API:BlendColors|BlendColors]]()
 
* [http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:min Math.min]()
 
* [http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:min Math.min]()
 +
 +
 +
{{API:Color/navbox}}

Latest revision as of 23:40, 11 September 2013

Returns a Color object that is the blended color of the two input colors, (c1 and c2) but allows you to specify the amount of each color.

Usage

Color BlendColorsWeighted(c1, c2, c1_weight, c2_weight);


  • c1 Color. a color object created with CreateColor
  • c2 Color. a color object created with CreateColor
  • c1_weight integer. amount of first color
  • c2_weight integer. amount of second color

Notes

The weights of the two colors are converted to a ratio out of 100%. (1:2 means one part of the first to two parts of the second. Or 33% of the first to 66% of the second.)

Examples

var Red = CreateColor(255, 0, 0);	//Creates a red color.
 
var Blue = CreateColor(0, 255, 0);	//Creates a blue color.
 
var Blend = BlendColorsWeighted(Red, Blue, 2, 1);	//Creates a reddish purple color by blending the two colors with 2 parts red to 1 part blue.

BlendColorsWeighted can be adapted for the more familiar alpha blending method as follows:

//Alpha can be between 0 and 1
function AlphaBlend (Color,SourceColor,Alpha) {
	Alpha = Math.min(Math.max(Alpha,0.0),1.0);	//Clamp alpha to 0-1
	return BlendColorsWeighted(Color,SourceColor,Alpha,1.0 - Alpha);
}

See also


API:Color/navbox