我怎样才能把这个SVG文件写得更紧凑呢?

发布于 2024-10-08 10:43:20 字数 1740 浏览 6 评论 0原文

这段代码是否可以写得更紧凑?我有一张桌子,我想旋转它。然而我正在使用四个不同的对象:TableWithCharisW..S

<?xml version="1.0"?>
<svg width="704" height="702" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <!-- objects -->
        <rect id="Chair" width="40" height="40" />
        <rect id="Table" width="130" height="65" />
        <g id="TableWithChairs">
            <use xlink:href="#Table" />
            <use xlink:href="#Chair" x="12.5" y="70" />
            <use xlink:href="#Chair" x="77.5" y="70" />
        </g>
        <use id="TableWithChairsW" xlink:href="#TableWithChairs" transform="rotate(90) translate(0, -65)" />
        <use id="TableWithChairsN" xlink:href="#TableWithChairs" transform="rotate(180) translate(-130, -65)" />
        <use id="TableWithChairsE" xlink:href="#TableWithChairs" transform="rotate(-90) translate(-130, 0)" />
        <use id="TableWithChairsS" xlink:href="#TableWithChairs" />
    </defs> 

    <!-- room background -->
    <rect x="0" y="0" width="704" height="702" fill="white"/>

    <!-- tables vertical -->
    <use xlink:href="#TableWithChairsE" x="497" y="117" />
    <use xlink:href="#TableWithChairsE" x="497" y="247" />
    <use xlink:href="#TableWithChairsW" x="142" y="117" />
    <use xlink:href="#TableWithChairsW" x="142" y="247" />

    <!-- tables horizontal -->
    <use xlink:href="#TableWithChairsN" x="207" y="117" />
    <use xlink:href="#TableWithChairsN" x="337" y="117" />
    <use xlink:href="#TableWithChairsS" x="207" y="312" />
    <use xlink:href="#TableWithChairsS" x="337" y="312" />
</svg>

Is it possible to write this code more compact? I have a table, which I would like to rotate. Yet I'm using four different objects: TableWithCharisW..S

<?xml version="1.0"?>
<svg width="704" height="702" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <!-- objects -->
        <rect id="Chair" width="40" height="40" />
        <rect id="Table" width="130" height="65" />
        <g id="TableWithChairs">
            <use xlink:href="#Table" />
            <use xlink:href="#Chair" x="12.5" y="70" />
            <use xlink:href="#Chair" x="77.5" y="70" />
        </g>
        <use id="TableWithChairsW" xlink:href="#TableWithChairs" transform="rotate(90) translate(0, -65)" />
        <use id="TableWithChairsN" xlink:href="#TableWithChairs" transform="rotate(180) translate(-130, -65)" />
        <use id="TableWithChairsE" xlink:href="#TableWithChairs" transform="rotate(-90) translate(-130, 0)" />
        <use id="TableWithChairsS" xlink:href="#TableWithChairs" />
    </defs> 

    <!-- room background -->
    <rect x="0" y="0" width="704" height="702" fill="white"/>

    <!-- tables vertical -->
    <use xlink:href="#TableWithChairsE" x="497" y="117" />
    <use xlink:href="#TableWithChairsE" x="497" y="247" />
    <use xlink:href="#TableWithChairsW" x="142" y="117" />
    <use xlink:href="#TableWithChairsW" x="142" y="247" />

    <!-- tables horizontal -->
    <use xlink:href="#TableWithChairsN" x="207" y="117" />
    <use xlink:href="#TableWithChairsN" x="337" y="117" />
    <use xlink:href="#TableWithChairsS" x="207" y="312" />
    <use xlink:href="#TableWithChairsS" x="337" y="312" />
</svg>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2024-10-15 10:43:20

如果去掉E、W、N、S这4个中间阶段,直接将transform属性放在垂直和水平表格的标签上,会更紧凑。但它的模块化程度也较低,并且更难以理解,因此您可能不想这样做。我认为没有一种方法可以使其更加紧凑,而又不会失去每次旋转仅一次的优点(除非您将缩短长名称视为“使其更加紧凑”:-)

It would be more compact if you get rid of the 4 intermediate stages E, W, N, S and just put the transform attribute directly on the tags for the vertical and horizontal tables. But it would also be less modular and more difficult to understand, so you may not want to do it. I don't think there's a way to make it more compact without losing the advantages of doing each of the rotations only once (except if you count shortening the long names as "making it more compact" :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文