【发布时间】:2016-06-03 05:46:55
【问题描述】:
我正在将 Flash 应用程序转换为 HTML5 Canvas。大部分开发已经完成,但是为了处理颜色,在 flash 应用程序中有这样的代码:
matrix = new Matrix ();
matrix.createGradientBox (600, ColorHeight * 1200, 0, 80, ColorHeight * -600);
Animation_gradient_mc.clear ();
Animation_gradient_mc.beginGradientFill (fillType, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
CreateJS 中径向渐变的声明如下:
beginRadialGradientFill(colors, ratios, x0, y0, r0, x1, y1, r1 )
有人知道将矩阵应用于渐变填充的方法吗?
任何帮助将不胜感激。
提前致谢
编辑
以下是我尝试重现的渐变的一些示例:
如您所见,它以标准径向渐变开始。
但是,它也可能显得拉伸,我认为这是矩阵的帮助。
我试图通过创建一个带有矩阵的 createjs.Graphics.Fill 来创建相同的效果,但它似乎没有做任何事情:
var matrix = new VacpMatrix();
matrix.createGradientBox(
600,
discharge_gradient.color_height * 1200,
0,
80,
discharge_gradient.color_height * -600
);
// test_graphics.append(new createjs.Graphics.Fill('#0000ff', matrix));
console.log('matrix', matrix);
test_graphics.append(new createjs.Graphics.Fill('#ff0000', matrix).radialGradient(
discharge_gradient.colors,
discharge_gradient.ratios,
discharge_gradient.x0,
discharge_gradient.y0,
discharge_gradient.r0,
discharge_gradient.x1,
discharge_gradient.y1,
discharge_gradient.r1
));
var discharge_shape = new createjs.Shape(test_graphics);
我扩展了 Matrix2d 类以使用来自 openfl 项目的代码添加一个 createGradientBox 方法:
p.createGradientBox = function (width, height, rotation, tx, ty) {
if (_.isUndefined(rotation) || _.isNull(rotation)) {
rotation = 0;
}
if (_.isUndefined(tx) || _.isNull(tx)) {
tx = 0;
}
if (_.isUndefined(ty) || _.isNull(ty)) {
ty = 0;
}
var a = width / 1638.4,
d = height / 1638.4;
// Rotation is clockwise
if (rotation != 0) {
var cos = math.cos(rotation),
sin = math.sin(rotation);
this.b = sin * d;
this.c = -sin * a;
this.a = a * cos;
this.d = d * cos;
} else {
this.b = 0;
this.c = 0;
}
this.tx = tx + width / 2;
this.ty = ty + height / 2;
}
我希望额外的信息有用。
【问题讨论】:
-
您是否有一个使用 CreateJS 无法重现的矩阵制作的 AS3 渐变的视觉示例?显示您尝试过的代码,以便其他人可以看到您要去哪里...
标签: html flash canvas html5-canvas createjs