【发布时间】:2023-03-15 01:31:01
【问题描述】:
我想实现一些镂空风格。
就这样????
而且我是用canvas来实现这种风格的,但是不知道怎么用paper Js来实现同样的风格。
在画布中,有两种方式来绘制路径,顺时针和逆时针,如果你使用逆时针,它会忽略填充颜色。 所以我使用逆时针绘制路径来实现镂空式,
# use canvas
const canvas = document.querySelector('#myCanvas');
const ctx = canvas.getContext('2d');
const pointsOutSide = [{
x: 100,
y: 100,
}, {
x: 400,
y: 100,
},{
x: 400,
y: 400,
},{
x: 100,
y: 400,
}]
const pointsIntSideRevers = [{
x: 300,
y: 200,
}, {
x: 200,
y: 200,
}, {
x: 200,
y: 300,
}, {
x: 300,
y: 300,
}]
for(let i = 0; i < pointsOutSide.length; i++) {
const { x, y } = pointsOutSide[i];
if(i === 0) {
ctx.moveTo(x, y);
continue;
}
ctx.lineTo(x, y);
}
ctx.closePath();
for(let i = 0; i < pointsIntSideRevers.length; i++) {
const { x, y } = pointsIntSideRevers[i];
if(i === 0) {
ctx.moveTo(x, y);
continue;
}
ctx.lineTo(x, y);
}
ctx.closePath();
ctx.fillStyle = 'rgba(0, 0, 0, 0.8)';
ctx.fill();
但是当我通过paper js使用相同的方式时,它不起作用,并且我检查了paper js的源代码,它使用了本机canvas API。我不知道它们为什么不同。
这是论文Js版????。其实这不是我想要的
【问题讨论】:
标签: javascript canvas paperjs