SVG angular gradient

2020-02-05 06:35发布

Is there a way to do an 'angular gradient' in SVG?

(I don't know the official term -- it's the kind of gradient you see in color-pickers, where it varies by angle.)

SVG seems to support only linear and radial gradients, but I'm thinking there might be some way to use a transform to simulate what I want.

thanks!

标签: svg gradient
6条回答
姐就是有狂的资本
2楼-- · 2020-02-05 06:42

If you dig into this page, you'll find code that approximates a conic gradient in SVG by drawing it as a series of 1 degree arcs.

查看更多
Fickle 薄情
3楼-- · 2020-02-05 06:47

There's no standard support to do angular (conical) gradients.

But see http://wiki.inkscape.org/wiki/index.php/Advanced_Gradients#Conical_gradient for some approximation methods (source code not included, though). Examples on that link do not work.

查看更多
别忘想泡老子
4楼-- · 2020-02-05 06:55

Here is a possible vector conical gradient, but only VML (+IE) can do it...:

http://midiwebconcept.free.fr/Demos/degradeconique.htm

查看更多
贼婆χ
5楼-- · 2020-02-05 06:57

http://en.wikipedia.org/wiki/File:Blended_colour_wheel.svg uses an innovative technique to approximate it.

查看更多
Deceive 欺骗
6楼-- · 2020-02-05 06:58

In my answer to this similar question, I used six linear gradients to approximate a conical gradient. If you are only needing the gradient for the stroke/perimeter of a circle, rather than the fill, then it should be a good enough approximation.

svg multiple color on circle stroke

查看更多
beautiful°
7楼-- · 2020-02-05 06:59

Here is how to do it using patterns: https://jsfiddle.net/prozoroff/8eodzrke/

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="800" width="800">
    <defs>
        <linearGradient id="Gradient1" gradientTransform="rotate(90)">
            <stop offset="0%" stop-color="#ff0000"/>
            <stop offset="100%" stop-color="#00ff00"/>
        </linearGradient>
        <linearGradient id="Gradient2" gradientTransform="rotate(90)">
            <stop offset="0%" stop-color="#0000ff"/>
            <stop offset="100%" stop-color="#00ff00"/>
        </linearGradient>
        <pattern id="Pattern" x="0" y="0" width="600" height="600" patternUnits="userSpaceOnUse">
            <g transform="rotate(0, 300, 300)">
                <rect shape-rendering="crispEdges" x="0" y="0" width="300" height="600" fill="url(#Gradient1)"/>
                <rect shape-rendering="crispEdges"  x="300" y="0" width="300" height="600" fill="url(#Gradient2)"/>
            </g>
       </pattern>
  </defs>
  <path id='arc5' style="stroke: url(#Pattern);" fill='transparent' stroke-width='60' d='M 364 58 A 250 250 0 1 1 235 58'/>
</svg>

查看更多
登录 后发表回答