【发布时间】:2021-04-20 13:07:52
【问题描述】:
正如您在附图中看到的那样,它有菱形,里面有椭圆,几乎是透明的。
但这只是一张图片。
如何使用 createjs 创建它?
更详细的问题描述:
你在图片中看到的并不是我所需要的。 理想情况下,我的任务是用这个菱形制作两个三角形,里面有一个椭圆。
椭圆应该在三角形中创建某种透明度,以便该三角形下方的所有元素都可以看到。
我的实现:
我根据这个例子做一个三角形: (感谢fiddle)
(createjs.Graphics.Polygon = function(x, y, points) {
this.x = x;
this.y = y;
this.points = points;
}).prototype.exec = function(ctx) {
// Start at the end to simplify loop
var end = this.points[this.points.length - 1];
ctx.moveTo(end.x, end.y);
this.points.forEach(function(point) {
ctx.lineTo(point.x, point.y);
});
};
createjs.Graphics.prototype.drawPolygon = function(x, y, args) {
var points = [];
if (Array.isArray(args)) {
args.forEach(function(point) {
point = Array.isArray(point) ? {x:point[0], y:point[1]} : point;
points.push(point);
});
} else {
args = Array.prototype.slice.call(arguments).slice(2);
var px = null;
args.forEach(function(val) {
if (px === null) {
px = val;
} else {
points.push({x: px, y: val});
px = null;
}
});
}
return this.append(new createjs.Graphics.Polygon(x, y, points));
};
stage = new createjs.Stage("demoCanvas");
poly1 = new createjs.Shape();
poly1.graphics.beginFill("Red").drawPolygon(0,0,10,10,10,40,40,30,60,5,30,0);
poly1.x = 10;
poly1.y = 10;
stage.addChild(poly1);
stage.update();
(如果有更方便甚至正确的方法来制作三角形,这将有助于解决我的问题,我很乐意接受你的解决方案。
接下来,我只是将用 drawEllipse 绘制的椭圆覆盖在这个三角形的顶部。
我知道我可能做错了什么,这就是我在这里的原因。
任何帮助都会被接受!
【问题讨论】:
标签: javascript canvas createjs