有什么技巧可以绘制动画路径吗?
有没有办法用石英模拟手写?
我的意思是,A、B、C 点之间有一条路径。 我希望路径从 A 点出来,然后以动画方式到达 B 点,然后到达 C 点。
我想到的是两种选择:
丑陋 - 创建路径,然后遮罩它并移动遮罩以显示路径。 需要花费大量时间来创建不可靠且丑陋的黑客
移动点 A、B、C 并在它们之间绘制线。
有什么方法可以沿着离开轨迹的路径制作一个圆圈的动画吗?
有什么技巧、例子吗?
谢谢。
Is there a way to simulate handwriting using quartz?
I mean there is a path between points A, B and C.
I want path to come out of point A and go animated to point B and then C.
What comes to mind is two options to do it:
Ugly- Create path then mask it and move mask around to reveal a path.
Takes a lot of time to create and unreliable and ugly hackmove points A,B,C and draw line between them.
Some way to animate a circle along a path leaving the trail?
Any techniques, examples?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
制作一个
CAShapeLayer
,然后为其路径
设置动画。Make a
CAShapeLayer
and then animate itspath
.正如上面评论中提到的,理想的 API 应该是可以让您沿着路径绘制任意线段的 API,但我还没有看到任何这样的 API。
另一种方法是将路径定义为谨慎的分段。 然后使用 NSBezierPath 的元素方法沿着路径行走,并在计时器上或使用 NSAnimation 绘制沿途的每个分段。 这种方法的问题是它不允许您使用任何任意路径。
As mentioned in the comment above an ideal API would be one that would let you draw any arbitrary segment along the path but I have not seen any such API.
Another approach would be to define your path is discreet segments. Then use NSBezierPath's element methods to walk along the path and draw each segment along the way on a timer or using NSAnimation. The problem with this approach is that is does not let you use any arbitrary path.
贝塞尔曲线定义了一种基于不相关参数(通常称为 t)获取一组点的方法。 要渲染完整曲线,请评估 0 到 1 之间的 t,并从每个点到下一个点绘制一条线。 要渲染小于完整的曲线,请将 t 计算为从 0 到小于 1 的数字。 要动画绘制曲线,您可以评估点并在计时器上绘制线段。
您可以在任意 t 处分割贝塞尔曲线。 这样做将允许您将曲线传递给系统进行绘制,或在 CAShapeLayer 中使用。
手写字母通常是一系列贝塞尔曲线或贝塞尔样条线。 一条曲线的终点是下一条曲线的起点。 可以将 t 视为从零到样条曲线中的段数。 如果有 3 条曲线,则认为 t 从 0 到 3。当 t 在 1 和 2 之间时,您可以将整个第一段和第二段的一部分传递给系统进行绘制。
您可以阅读有关分割贝塞尔曲线的 DeCasteljau 算法。 下面是平面上三次贝塞尔曲线的代码示例:
因此,给定一系列描述手写字符的曲线,您可以从 0 到 T 进行动画处理,其中 T 是曲线的数量。 计算 t=T-floor(T),当 t 不为零时,用它在 n=floor(T) 处分割曲线。
A bezier curve defines a way to get a set of points based on an unrelated parameter, usually called t. To render the full curve, you evaluate t between 0 and 1 and draw a line from each point to the next. To render less than the full curve, you evaluate t from 0 to a number less than one. To animate drawing the curve, you could evaluate the points and draw the segments on a timer.
You can split a bezier curve at an arbitrary t. Doing that will allow you to pass the curve to the system to draw, or to use in a CAShapeLayer.
A handwritten letter will usually be a series of bezier curves, or a bezier spline. The end point of one curve is the start point of the next. Think of t as going from zero to the number of segments in the spline. If there are 3 curves, think of t as going from 0 to 3. When t is between 1 and 2, you would pass the whole first segment and part of the second segment to the system to draw.
You can read about DeCasteljau's algorithm for splitting bezier curves. Here is a code sample for a cubic bezier curve on a plane:
So given a series of curves that describe your handwritten character, you would animate from 0 to T, where T is the number of curves. calculate t=T-floor(T) and when t is not zero, use it to split the curve at n=floor(T).