RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 760071
Accepted
Alexandr_TT
Alexandr_TT
Asked:2020-12-18 23:11:22 +0000 UTC2020-12-18 23:11:22 +0000 UTC 2020-12-18 23:11:22 +0000 UTC

如何沿线创建图案或路径链

  • 772

我需要 pattern沿着一条线创建链。
我尝试以markers链节的形式创建,但我在标记沿path.

有没有其他方法可以做到这一点?
如果是,我的方法应该是什么?

预期的结果是这样的: 在此处输入图像描述

资源

css
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2020-12-19T00:49:08Z2020-12-19T00:49:08Z

    任何图像都可以使用以下命令沿着弯曲路径引导:

    <animateMotion  dur="4s" repeatCount="2">
                            <mpath xlink:href="#pathChain"/>
                    </animateMotion>            
    

    代码示例:

    <svg width="600" height="400" viewBox="80 100 400 300">
    
    <defs>
     <circle id="CirclePath" r="5" fill="red" />
    </defs>
      <path id="pathChain" d="M100,200 C100,100 250,100 250,200 S 400,300 400,200" stroke="grey" fill="none"/>
     
    <use  xlink:href="#CirclePath">
                    <animateMotion
                      dur="4s"
                      repeatCount="indefinite">
                            <mpath xlink:href="#pathChain"/>
                    </animateMotion>
                    
            </use> 
    </svg>

    但只有一个物体会沿着路径移动,即链条中的一个环节。要放置几十个链节,您将需要重复此命令数十次,并且无法优化代码。另外,定位和粘合相邻链接不可避免地会遇到困难。

    要沿弯曲路径放置文本,SVG 中有另一个命令 -<textPath>

    <svg width="590" height="560" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
      <defs>
      <path id="MyPath" d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80" stroke="black" fill="transparent"/>
      </defs>
      
        <text font-family="Verdana" font-size="10" textLength="400" lengthAdjust="spacing">
        <textPath xlink:href="#MyPath">
          O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-O-
        </textPath>
      </text>
    </svg> 

    上面的例子使用了来自 Enso @Michael Mullany 的回答的想法

    但是链条看起来不像我想要的那样。

    用更真实地模仿链式链接的 Unicode 字符替换字母怎么样?

    我决定使用 Unicode 字符 - “侧面的拉丁小写字母” -U+1D11 &#7441;以及连接相邻链节的连字符 -&#45;

    <svg width="600" height="400" viewBox="80 100 400 300">
     <path id="pathChain" d="M100,200 C100,100 250,100 250,200 S 400,300 400,200" stroke="grey" fill="none"/>
    
    
    <text font-size="36"  font-family="Times New Roman" fill="grey" >
    <textPath id="result"    xlink:href="#pathChain">
    <tspan dx="0" > &#7441; </tspan> <tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan>
    
    </textPath>
    </text>				
    			
    </svg>    

    <tspan dx="-15"> &#7441;</tspan>    , где 
    

    &#7441;- Unicode 字符,O侧面是拉丁文。

    dx="-15" - 此字符向左偏移。

    另外,一个动画例子

    <svg width="600" height="400" viewBox="100 100 400 300">
    
     <path id="pathChain" d="M100,200 C100,100 250,100 250,200 S 400,300 400,200" stroke="grey" fill="none"/>
    
    <text font-size="36"  font-family="Times New Roman" fill="grey" >
    <textPath id="result"    xlink:href="#pathChain">
    <tspan dx="0" > &#7441; </tspan> <tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan>
    <animate  dur="10s" repeatCount="indefinite" attributeName="startOffset" values="1%;55%;1%"/> 
    </textPath>
    </text>				
    			
    </svg>   

    2018 年 12 月 16 日更新

    在中心减速时在轨迹的开始和结束处暂停的运动示例。

    该算法是通过重复动画属性开头和结尾的数字来实现的。values="1%;37%;55%;55%;1%;1%"

    整个动画的持续时间 <animate dur="12s"除以中的位置个数 values
    因此,动画的一部分将是2s,如果位置连续重复55%;55%,则在此点会有暂停。

    <svg width="600" height="400" viewBox="100 100 400 300">
    
     <path id="pathChain" d="M100,200 C100,100 250,100 250,200 S 400,300 400,200" stroke="grey" fill="none"/>
    
    <text font-size="36"  font-family="Times New Roman" fill="grey" >
    <textPath id="result"    xlink:href="#pathChain">
    <tspan dx="0" > &#7441; </tspan> <tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan><tspan dx="-15">   &#45; </tspan><tspan dx="-15"> &#7441;</tspan><tspan dx="-15">   &#45;</tspan><tspan dx="-15">   &#7441; </tspan>
    <animate  dur="12s" repeatCount="indefinite" attributeName="startOffset" values="1%;37%;55%;55%;1%;1%"/> 
    </textPath>
    </text>				
    			
    </svg>   

    答案来源:如何在 svg 中沿笔划或路径绘制图案?@Alexandr_TT

    相关主题 -在动画中使用 Unicode 字符

    • 11

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5