【问题标题】:SVG gradient gradient units vs gradienttransform - not the same gradientSVG渐变渐变单位与渐变变换 - 不同的渐变
【发布时间】:2022-01-19 14:41:25
【问题描述】:

我试图弄清楚从梯度转换到梯度单元的转换。我得到不同的梯度分布。为什么?

<svg width="540" height="540" xmlns="http://www.w3.org/2000/svg" >
  <defs>
    <linearGradient id="linear1" gradientTransform="rotate(45 0.5 0.5)" spreadMethod="pad">
      <stop offset="0%" stop-color="gold"/>
      <stop offset="100%" stop-color="blue"/>
    </linearGradient>
    <linearGradient id="linear2" x1="0%" y1="0%" x2="100%" y2="100%" spreadMethod="pad">
      <stop offset="0%" stop-color="gold"/>
      <stop offset="100%" stop-color="blue"/>
    </linearGradient>
  </defs>
  
  <rect fill="url(#linear1)" x="0" y="0" width="270" height="270" />
  <rect fill="url(#linear2)" x="0" y="270" width="270" height="270" />
</svg>

这2个渐变不一样:

【问题讨论】:

  • @RobertLongson 意思是 x1 应该是 13%,x2 应该是 87%(近似垃圾数字) - 我发现了 spreadMethod="repeat" 的问题。

标签: svg gradient


【解决方案1】:

因为一个矩形的左右边之间的距离不等于将它旋转 45 度时从一个角到对角的距离。

  1. 左右两侧相距 270 个单位(默认 x2 为 100%,其他默认为 0%)。

  2. 两个角相距 270 * √2 个单位

因此,鉴于旋转变换是距离不变的,因此 x1,y1 和 x2,y2 之间的距离在每种情况下都是不同的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-21
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2018-09-14
    相关资源
    最近更新 更多