tags:

views:

104

answers:

3

SVG linear gradient

What a proper way to do a gradient like this? I tried this SVG:

<linearGradient id="hue" x1="0" y1="1" x2="0" y2="0">
    <stop offset="0%" stop-color="#ff0000"/>
    <stop offset="17%" stop-color="#ffff00"/>
    <stop offset="34%" stop-color="#00ff00"/>
    <stop offset="50%" stop-color="#00ffff"/>
    <stop offset="66%" stop-color="#0000ff"/>
    <stop offset="82%" stop-color="#ff00ff"/>
    <stop offset="100%" stop-color="#ff0000"/>
</linearGradient>

It works, but still not good enough:

SVG linear gradient

I can see the difference between those two gradients. Is there a better way of doing it?

A: 
    <linearGradient
   id="linearGradient3706">
  <stop
     style="stop-color:#ff1c1c;stop-opacity:1;"
     offset="0"
     id="stop3708" />
  <stop
     id="stop3728"
     offset="0.16105497"
     style="stop-color:#fd00ca;stop-opacity:1;" />
  <stop
     id="stop3724"
     offset="0.35173747"
     style="stop-color:#0202ff;stop-opacity:1;" />
  <stop
     id="stop3720"
     offset="0.48789391"
     style="stop-color:#02fff9;stop-opacity:1;" />
  <stop
     id="stop3718"
     offset="0.70091939"
     style="stop-color:#60ff18;stop-opacity:1;" />
  <stop
     id="stop3714"
     offset="0.83720928"
     style="stop-color:#ffef15;stop-opacity:1;" />
  <stop
     style="stop-color:#ff0000;stop-opacity:1;"
     offset="1"
     id="stop3710" />
</linearGradient>

works for me (made with inskape)

Josh
This is almost the same as I posted in the beginning. I'm hoping to find a way to do a transition from one color to another by changing only the hue.
NV
@NV so you only want to have two stops?
Russell Leggett
+1  A: 

If it's acceptable to generate the SVG with Javascript you might want to look at: http://stackoverflow.com/questions/2593832/how-to-interpolate-hue-values-in-hsv-colour-space

or perhaps:

http://www.carto.net/papers/svg/gui/colourPicker/

Edit: Actually there is one here. would that be correct?

http://upload.wikimedia.org/wikipedia/commons/5/5d/HSV-RGB-comparison.svg

nicomen
A: 

Have you tried using better precision in your %? As Josh is showing, you can have sub-percent precision and space your stops better.

Russell Leggett