I have a very simple path within a 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 like to achive is that I have 3 separate gradients or filling spaces:
- The first one is from the inner curve to the center of the bended tube (curve).
- The second one is the center area.
- The third one from the center area to the outer curve of the tube.
Alternatively I could also use a single gradient with multiple stop colors.
The following image illustrates the wanted result: https://i.imgur.com/oPEFAZT.png In this case the rectangles I added illustrate the gradient that I want to use along the whole curve.
I did some research regarding advanced gradients in SVG but I was not able to understand how to apply them or if that is even necessary. I understand how to apply radial and linear gradients to rectangles or even to curves but that did not deliver the expected result.
I also found Can I apply a gradient along an SVG path? which creates a gradient in the tube from left to right (so to say) and I'd like it from top to bottom.
Do you guys have any ideas how to solve this?
You can may get the result you want by using
filter
s with blur or lighting. Here is a good article on advanced filters: https://www.smashingmagazine.com/2015/05/why-the-svg-filter-is-awesome/In general it is not possible to create gradients that flow along a path.
However, in cases like yours which only involve straight pieces and circular arcs, you can achieve the effect by breaking the shape up into those sections. Then you apply a different gradient to each part. You use a
<linearGradient>
for the straight sections, and a<radialGredient>
for the curved sections.In the example below, I have used a very simplified gradient for the "pipe" effect. You will probably wish to add more stops to yours to give a better 3D effect.