Shader Class
Shader is used to create a various types of color gradients. An instance of Shader is installed in a Paint calling paint.shader = shader. After that any object (other than a bitmap) that is drawn with that paint will get its color(s) from the shader.
Item Index
Methods
- bitmap static
- linear static
- resetLocalMatrix
- setLocalMatrix
- setLocalMatrix
- sweep static
Methods
bitmap
fileName
tileModeX
tileModeY
Call this to create a new shader that will draw with the specified bitmap. The bitma gradient is used to apply texture onto various irregular shapes.
Parameters:
-
fileName
StringThe bitmap to use inside the shader.
-
tileModeX
SymbolThe tiling mode to use when sampling the bitmap in the x-direction. For supported modes see Gradient modes.
- #clamp - Draw bitmap only ones.
- #repeat - Repeat bitmap more times.
- #mirror - Repeat bitmap more times, but mirror turned.
-
tileModeY
SymbolThe tiling mode to use when sampling the bitmap in the y-direction. For supported modes see Gradient modes.
- #clamp - Draw bitmap only ones.
- #repeat - Repeat bitmap more times.
- #mirror - Repeat bitmap more times, but mirror turned.
Returns:
Example:
this._path = Path.fromSVG("M1....8.63z");
// resize and place path ...
// create paint object
var paint = new Paint();
paint.shader = Shader.bitmap("app://img.png", #clamp, #clamp);
// draw vector
canvas.drawPath(this._path, paint);
linear
pts
clrs
pos
mode
This function creates a linear gradient.
Parameters:
-
pts
ObjectThe start and end points for the gradient.
-
clrs
ArrayThe array of colors, to be distributed between the two points.
-
pos
ArrayArray of float values, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the colors are distributed evenly between the start and end point. If this is not null, the values must begin with 0, end with 1.0, and intermediate values must be strictly increasing.
-
mode
SymbolIntege current version this parameter is ignored. It cancel be for example null.
Returns:
Example:
this._path = Path.fromSVG("M1....8.63z");
// resize and place path ...
// create paint object
var paint = new Paint();
var pts = {
start :
{
x: System.width / 2,
y : System.height / 4,
},
end :
{
x: System.width / 2,
y : 3 * System.height / 4,
}
}
var clrs = new Array(0xffff0000, 0xff00ff00, 0xff0000ff);
var pos = new Array(0.2, 0.5, 0.8);
paint.shader = Shader.linear(pts, clrs, pos, 0);
// draw vector
canvas.drawPath(this._path, paint);
resetLocalMatrix
()
Reset the shader's local matrix to identity.
setLocalMatrix
localMatrix
Set the shader's local matrix.
Parameters:
-
localMatrix
MatrixThe shader's new local matrix.
sweep
cx
cy
clrs
pos
This function creates a sweep gradient.
Parameters:
-
cx
IntegerThe X coordinate of the center of the sweep.
-
cy
IntegerThe Y coordinate of the center of the sweep.
-
clrs
ArrayThe array[count] of colors, to be distributed around the center.
-
pos
ArrayThe array of float values, or NULL, of the relative position of each corresponding color in the colors array.
- If this is NULL, the the colors are distributed evenly between the center and edge of the circle.
- If this is not null, the values must begin with 0, end with 1.0, and intermediate values must be strictly increasing.
Returns:
Example:
this._path = Path.fromSVG("M1....8.63z");
// resize and place path ..
// create paint object
var paint = new Paint();
var pts = {
start :
{
x: System.width / 2,
y : System.height / 4,
},
end :
{
x: System.width / 2,
y : 3 * System.height / 4,
}
}
var clrs = new Array(0xffff0000, 0xff00ff00, 0xff0000ff);
var pos = new Array(0.0, 0.5, 1.0);
paint.shader = Shader.sweep(System.width / 2, System.height / 2, clrs, pos);
// draw vector
canvas.drawPath(this._path, paint);