Gradient across path in SVG -


i have simple path within svg.

<svg     xmlns="http://www.w3.org/2000/svg"     xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0 0 61 57"      version="1.1" x="0px" y="0px">     <defs>         <style type="text/css"><![cdata[             ]]>         </style>     </defs>     <path id="pipe" d="         m8.0178,52.0035         l27.0178,52.0035         c42.4568,52.0035 55.0178,39.4425 55.0178,24.0035         l55.0178,8.0035         l43.0178,8.0035         l43.0178,24.0035         c43.0178,32.8255 35.8398,40.0035 27.0178,40.0035         l8.0178,40.0035         l8.0178,52.0035         z">     </path> </svg> 

(preview: https://i.imgur.com/nvnxcrg.png)

what i'd achive have 3 separate gradients or filling spaces:

  • the first 1 inner curve center of bended tube (curve).
  • the second 1 center area.
  • the third 1 center area outer curve of tube.

alternatively use single gradient multiple stop colors.

the following image illustrates wanted result: https://i.imgur.com/opefazt.png in case rectangles added illustrate gradient want use along whole curve.

i did research regarding advanced gradients in svg not able understand how apply them or if necessary. understand how apply radial , linear gradients rectangles or curves did not deliver expected result.

i found can apply gradient along svg path? creates gradient in tube left right (so say) , i'd top bottom.

do guys have ideas how solve this?

in general not possible create gradients flow along path.

however, in cases yours involve straight pieces , circular arcs, can achieve effect breaking shape sections. apply different gradient each part. use <lineargradient> straight sections, , <radialgredient> curved sections.

in example below, have used simplified gradient "pipe" effect. wish add more stops yours give better 3d effect.

<svg xmlns="http://www.w3.org/2000/svg"      xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0 0 61 57"       version="1.1" x="0px" y="0px">      <defs>        <lineargradient id="horizontalpipe" x2="0" y2="1">          <stop offset="0" stop-color="white"/>          <stop offset="0.25" stop-color="black"/>          <stop offset="0.75" stop-color="black"/>          <stop offset="1" stop-color="white"/>        </lineargradient>        <lineargradient id="verticalpipe">          <stop offset="0" stop-color="white"/>          <stop offset="0.25" stop-color="black"/>          <stop offset="0.75" stop-color="black"/>          <stop offset="1" stop-color="white"/>        </lineargradient>        <radialgradient id="curvedpipe" cx="0" cy="0" r="1">          <stop offset="0.57" stop-color="white"/>          <stop offset="0.677" stop-color="black"/>          <stop offset="0.893" stop-color="black"/>          <stop offset="1" stop-color="white"/>        </radialgradient>      </defs>            <rect x="8" y="40" width="19" height="12" fill="url(#horizontalpipe)"/>      <path d="m 27,40 16,16, 0,0,0 43,24 h 55 28,28, 0,0,1, 27,52 z" fill="url(#curvedpipe)"/>      <rect x="43" y="8" width="12" height="16" fill="url(#verticalpipe)"/>  </svg>


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -