如何将这个简单的图形转换为SVG XML路径?

huangapple go评论53阅读模式
英文:

How to make this simple figure to an SVG xml path?

问题

以下是翻译好的内容:

在过去的两天里,我一直在尝试将这个图标重新创建为SVG,但我只有一张图片。我对SVG编码非常陌生。

如何将这个简单的图形转换为SVG XML路径?

我尝试编码它,但这是我得到的全部内容:

<svg width="100" height="100"><path d="M50 0, L 100 100, L 50 85, L 0 100, Z"/></svg>

也许你可以帮我解决这个问题。

提前感谢!

英文:

In the last two days I'm trying to recreate this icon into an svg which I got only as an image. I'm really new to SVG coding.

如何将这个简单的图形转换为SVG XML路径?

I tried to code it, but this is all what I got:

<svg width="100" height="100"><path d="M50 0, L 100 100, L 50 85, L 0 100, Z"/></svg>

Maybe you can help me with that.

Thanks in advance!

答案1

得分: 0

根据评论中的建议(并且您已经开始自己操作),您可以使用路径元素。您可能需要一个用于绘制的编辑器。

我在这里建议的另一种方法是使用不同的基本元素(例如线条)来“构建”形状,以创建蒙版。这需要更多的代码,但更容易修改。

<svg viewBox="0 0 100 100" width="300">
  <defs>
    <mask id="m1" stroke-linecap="round"
      stroke-width="12" stroke="white">
      <g transform="translate(50 30)">
        <line x2="40" transform="rotate(115)"/>
        <line x2="40" transform="rotate(65)"/>
        <line y2="30"/>
      </g>
      <line transform="translate(50 30) rotate(65)
        translate(40 0) rotate(130)" x2="30"/>
      <line transform="translate(50 30) rotate(115)
        translate(40 0) rotate(-130)" x2="30"/>
    </mask>
  </defs>
  <rect width="100" height="100" fill="black"/>
  <rect mask="url(#m1)" width="100" height="100"
    fill="white"/>
</svg>
英文:

Like suggested in the comments (and you started doing yourself) you can use a path element. And you probably need an editor for drawing it.

The alternative that I suggest here is to "construct" the shape using different basic elements (here lines) to create a mask. Its more code, but easier to modify.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;svg viewBox=&quot;0 0 100 100&quot; width=&quot;300&quot;&gt;
  &lt;defs&gt;
    &lt;mask id=&quot;m1&quot; stroke-linecap=&quot;round&quot;
      stroke-width=&quot;12&quot; stroke=&quot;white&quot;&gt;
      &lt;g transform=&quot;translate(50 30)&quot;&gt;
        &lt;line x2=&quot;40&quot; transform=&quot;rotate(115)&quot; /&gt;
        &lt;line x2=&quot;40&quot; transform=&quot;rotate(65)&quot; /&gt;
        &lt;line y2=&quot;30&quot; /&gt;
      &lt;/g&gt;
      &lt;line transform=&quot;translate(50 30) rotate(65)
        translate(40 0) rotate(130)&quot; x2=&quot;30&quot; /&gt;
      &lt;line transform=&quot;translate(50 30) rotate(115)
        translate(40 0) rotate(-130)&quot; x2=&quot;30&quot;/&gt;
    &lt;/mask&gt;
  &lt;/defs&gt;
  &lt;rect width=&quot;100&quot; height=&quot;100&quot; fill=&quot;black&quot;/&gt;
  &lt;rect mask=&quot;url(#m1)&quot; width=&quot;100&quot; height=&quot;100&quot;
    fill=&quot;white&quot;/&gt;
&lt;/svg&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月7日 05:12:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定