javascript - 如何模糊 Paper.js 中的封闭路径元素?
问题描述
是否可以使用paperjs模糊具有填充的封闭路径元素?我是否必须为要模糊的每条路径创建一个 SVG feGaussianBlur 原语?如果画布上有几百个路径元素,这将如何影响性能?我考虑过使用带有一些颜色魔法的 shadowBlur,阴影将与所选路径匹配,但效果并不完全相同。我不想使用光栅。
解决方案
一个技巧可能是使用shadowBlur
项目的属性。
唯一的问题是只有在项目有填充时才会绘制阴影。
而且我们不希望显示填充,而只显示阴影。
所以我们可以巧妙地使用混合模式来隐藏填充而不是阴影。
这是一个简单的草图来证明这一点。
new Path.Circle({
center: view.center,
radius: 50,
shadowColor: 'black',
shadowBlur: 20,
selected: true,
// set a fill color to make sure that the shadow is displayed
fillColor: 'white',
// use blendmode to hide the fill and only see the shadow
blendMode: 'multiply',
});
编辑
当试图将项目堆叠在一起时,这种技术确实似乎达到了极限。我们可以通过将项目包装到具有混合模式的组中
来防止混合模式“溢出” 。这会影响子混合模式的范围。
但是仍然有一个技巧可以将这些项目组合在一起。
这是一个草图,展示了我停止调查的地方。
我很确定您可以按照这条路线找到解决方案。multiply
source-over
function drawBlurryCircle(center, radius, blurAmount, color) {
const circle = new Path.Circle({
center,
radius,
shadowColor: color,
shadowBlur: blurAmount,
// set a fill color to make sure that the shadow is displayed
fillColor: 'white',
// use blendmode to hide the fill and only see the shadow
blendMode: 'multiply'
});
const blurPlaceholder = circle
.clone()
.set({ shadowColor: null, fillColor: null })
.scale((circle.bounds.width + (blurAmount * 2)) / circle.bounds.width);
return new Group({
children: [circle, blurPlaceholder],
blendMode: 'source-over'
});
}
drawBlurryCircle(view.center, 50, 20, 'red');
drawBlurryCircle(view.center + 30, 40, 30, 'lime');
drawBlurryCircle(view.center + 60, 30, 30, 'blue');
推荐阅读
- sonos - 尝试获取家庭时发出无效访问令牌
- python - 将从 HTML 表中抓取的数据写入 CSV 文件
- r - 基于 SOAP 请求 (RCurl) 的结果在 R 中创建数据框的问题
- sql - 选择中的 SQL 子查询,在一列中返回多条记录
- php - 未定义的变量:警报 Laravel 5.6
- javascript - 使用 wkhtmltopdf 时如何在 JavaScript 中以像素为单位获取页面宽度和高度
- javascript - 如何在单个数据表数组列中组合姓氏名字中间名?- PHP
- python - 我在 tkinter 上做错了什么?
- airflow - 何时评估气流 dag 定义?
- haskell - 试图理解 zip