- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我有两条路:
var path1 = "M2337.8,0.1c-346.8,7.6-415.8,270.8-934.3,244.7 c-330.4-16.6-389.1-110.8-677.8-101.3c-321,10.5-403.4,252.6-592.3,252.6C73,396.1,29.8,372.8,0,341.9v451.8h2778V200 C2692.9,103.1,2538.6-4.3,2337.8,0.1z",
path2 = M2337.8,326.3C1991,333.9,1845,45.9,1472,45.9 c-334.4,0-390,181.9-639,181.9C473,227.8,400.3,0,195.7,0C84.5,0,0,98.3,0,146.1v562.6h2778V62.9 C2686,199.8,2538.6,321.9,2337.8,326.3z
我可以使用 paper.js 为其制作动画吗?谢谢。
最佳答案
这是我在之前的一个项目中使用的算法:
看看这个Sketch进行演示。
// create paths
var pathB = new Path.Circle(view.center, 200);
var pathA = new Path.Rectangle(view.center - 100, new Size(200));
var morphingPath = new MorphingPath(pathA, pathB);
// apply some styling
pathA.strokeColor = 'red';
pathB.strokeColor = 'blue';
morphingPath.path.fullySelected = true;
// animate morphing
function onFrame(event)
{
// with values from 0 to 1
morphingPath.morph(Math.abs(Math.sin(event.count * 0.01)));
}
/**
* A path that can be morphed between two other paths.
* @param {Path} path1
* @param {Path} path2
* @constructor
*/
function MorphingPath(path1, path2)
{
// internal variables
var self = this,
clone1,
clone2;
//
// API
//
// allow direct access to morphing path
self.path = null;
/**
* interpolate path from path1 to path2
* @param time must be a value from 0 to 1
*/
self.morph = function (time)
{
var segments = [];
for (var i = 0; i < self.path.segments.length; i++)
{
// morph segments
var segment1 = clone1.segments[ i ],
segment2 = clone2.segments[ i ],
point = rampPoint(segment1.point, segment2.point, time),
handleIn = rampPoint(segment1.handleIn, segment2.handleIn, time),
handleOut = rampPoint(segment1.handleOut, segment2.handleOut, time);
segments.push(new Segment(point, handleIn, handleOut));
}
self.path.segments = segments;
};
//
// INTERNAL METHODS
//
function init()
{
// store local copies of source paths
clone1 = path1.clone();
clone2 = path2.clone();
// hide them
clone1.visible = false;
clone2.visible = false;
// init morphing path
self.path = createMorphingPath();
}
/**
* Create the path that will later be morphed.
* Points are added when needed, for a smoother result.
* @returns {Path}
*/
function createMorphingPath()
{
var paths = [ clone1, clone2 ],
offsets = [ [], [] ];
// store paths segments offsets (except for first and last)
for (var i = 0; i < paths.length; i++)
{
var path = paths[ i ];
// loop segments
for (var j = 1; j < path.segments.length - 1; j++)
{
// store offset
offsets[ i ].push(path.segments[ j ].location.offset);
}
}
// add missing points
for (var i = 0; i < paths.length; i++)
{
// get current path offsets array
var pathOffsets = offsets[ i ];
// get a reference to the other path
var otherPath = i == 0 ? paths[ i + 1 ] : paths[ 0 ];
// loop current path offsets
for (var j = 0; j < pathOffsets.length; j++)
{
// add a corresponding point for that offset in the other path
otherPath.divideAt(otherPath.getLocationAt(pathOffsets[ j ]));
}
}
return clone1.clone();
}
function rampPoint(p1, p2, t)
{
return p1 + (p2 - p1) * t;
}
init();
}
关于svg - Paper.js 如何将一条路径转变为另一条路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50825267/
在尝试为 ContT monad 转换器建立一些直觉时,我(也许并不奇怪)发现自己很困惑。问题在于 shiftT 操作,它似乎没有做任何有用的事情。 首先是一个简单的例子,说明如何使用它 shiftT
我有 Item 1 Item 2 我想要切换 var elements = document.getElementsByName('R
执行此操作的最快方法是什么?左边括号中的变量返回 bool 值,它们表示窗口大小范围。 (例如,o1281 为 1281 及以上屏幕返回 true,o1025 为 1025 及以上屏幕返回 true,
我对编程还很陌生,但我的任务是维护一些由前员工创建的应用程序。我有一个 ?: 声明现在需要处理的不仅仅是真或假声明,但我不确定如何去做。有问题的代码是: MailDomainContext m
为什么 GMT-0400 在 1989 年之前转变为 GMT-0500? > new Date('1989-04-02T23:01:14.52Z') Sun Apr 02 1989 19:01:14
我们有一堆代理对(或 2 字节 utf8?)字符,例如 ��,这是作为 2 个字符存储为 UTF8 的祈祷 watch 情符号。在浏览器中呈现时,此字符串呈现为两个 ?? 例子:�� 我需要使用 ph
我知道我可以将字符串格式的 unixTime 转换为本地时间的毫秒val currentTimeMillis = serverTimeDateFormat.parse(iso8601).time 我想
我是一名优秀的程序员,十分优秀!