This filter applies a color transform to DisplayObject
. This filter comes handy when you need to play with colors in EaselJS.
In the following code snippet, you can see the definition of this filter:
ColorFilter ([redMultiplier=1] [greenMultiplier=1][blueMultiplier=1] [alphaMultiplier=1] [redOffset=0][greenOffset=0] [blueOffset=0] [alphaOffset=0])
The various parameters in this code snippet are as follows:
[redMultiplier=1]
– Number
: It is an optional parameter. It sets the value to multiply with the red channel. The value should be between 0 and 1.[greenMultiplier=1]
– Number
: It is an optional parameter. It sets the value to multiply with the green channel. The value should be between 0 and 1.[blueMultiplier=1]
– Number
: It is an optional parameter. It sets the value to multiply with the blue channel. The value should be between 0 and 1.[alphaMultiplier=1]
– Number
: It is an optional parameter. It sets the value to multiply with the alpha channel. The value should be between 0 and 1.[redOffset=0]
– Number
: It is an optional parameter. It sets the value to add to the red channel after it has been multiplied. The value should be between -255 and 255.[greenOffset=0]
– Number
: It is an optional parameter. It sets the value to add to the green channel after it has been multiplied. The value should be between -255 and 255.[blueOffset=0]
– Number
: It is an optional parameter. It sets the value to add to the blue channel after it has been multiplied. The value should be between -255 and 255. [alphaOffset=0]
– Number
: It is an optional parameter. It sets the value to add to the alpha channel after it has been multiplied. The value should be between -255 and 255.Here is an example of using this filter:
/* Add canvas and stage */ var canvas = document.getElementById("canvas"); var stage = new createjs.Stage(canvas); var shape = new createjs.Shape().set({x:100,y:100}); shape.graphics.beginFill("#ff0000").drawCircle(0,0,50); shape.filters = [ new createjs.ColorFilter(0,0,0,1, 0,0,255,0) ]; shape.cache(-50, -50, 100, 100); /* add shape to stage and update */ stage.addChild(shape); stage.update();
In this example, we created a red circle and then changed its color to blue using ColorFilter
. This is done by multiplying all the channels with 0 (except for the alpha channel, which is set to 1) and then adding the value 255 to the blue channel and 0 to the other channels.
52.14.240.252