gpt4 book ai didi

javascript - 为什么 SVG 线条/路径在彼此之上会产生不同的笔划?

转载 作者:行者123 更新时间:2023-11-29 20:42:48 28 4
gpt4 key购买 nike

我正在绘制一些具有相同笔划的路径,但有一些明显的重叠(动态创建和更新树)。在重叠区域,笔划看起来与非重叠区域(- 参见 b)不同(更暗和更粗 - 参见 a)。同样的效果对于不同的笔触颜色也很明显。

enter image description here

代码如下:

  path.p2 {
fill: none;
stroke: black;
stroke-width: 1px;
}
<svg height="500" width="400">
<path class="p2" d="M210 10 V 100 H 300 "/>
<path class="p2" d="M210 10 V 120 H 300 "/>
<path class="p2" d="M210 10 V 140 H 300 "/>
<path class="p2" d="M210 10 V 160 H 300 "/>
</svg>

是否有简单的 CSS、SVG 或 javascript 修复如何绘制这些路径(无需重新计算重叠区域和创建新路径)?

最佳答案

正如我评论过的,您可以将 shape-rendering: crispEdges 添加到 path.p2

MDN 引用:

crispEdges Indicates that the user agent shall attempt to emphasize the contrast between clean edges of artwork over rendering speed and geometric precision. To achieve crisp edges, the user agent might turn off anti-aliasing for all lines and curves or possibly just for straight lines which are close to vertical or horizontal. Also, the user agent might adjust line positions and line widths to align edges with device pixels.

svg {
outline:1px solid;
}
path.p2 {
fill: none;
stroke: black;
stroke-width: 1px;
shape-rendering: crispEdges;
}
<svg height="500" width="400">
<path class="p2" d="M210 10 V 100 H 300 "/>
<path class="p2" d="M210 10 V 120 H 300 "/>
<path class="p2" d="M210 10 V 140 H 300 "/>
<path class="p2" d="M210 10 V 160 H 300 "/>
</svg>

关于javascript - 为什么 SVG 线条/路径在彼此之上会产生不同的笔划?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55110846/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com