Inkscape.org
Beyond the Basics How do I get a concentric gradient that follows the shape of the object?
  1. #1
    tukykarmakar tukykarmakar @tukykarmakar
    *

    I need a single method to consistently generate a gradient going inwards from the edge of an object. For example, the bottom pill in the screenshot has a gradient going from dark blue in the outer edge to light purple in the centre, while maintaining a pill shape throughout the graident.

    I looked up online and found that people are using Extensions > Generate from Path > Interpolate Between Paths option to do this. But for my case, it's not following the shape, as shown in the pill above.

    The pill below was created using 3 shapes -- 2 semi-circles and a rectangle, with two different gradients. The semi-circles have a concentric gradient of two colours (using circular gradient in Fill menu), but the rectangle has 3 colours. The gradient in the bottom pill is shrinking down to essentially a line. If I want to have a smaller pill in the centre, there has to be 4 colours for the rectangle.

    The above example is easy and the solution seems to be specific to this arrangement. I have to think of a different solution based on the complexity of the shape. While the Interpolate method seems to be working for people online, I don't know why it's not working for my case. In fact, I noticed that simple polygons work, but shapes with spokes or curved edges don't work.

    Is there a method to get the gradient that isn't specific to the object shape? Am I using wrong settings in Interpolate?

    Inkscape
  2. #2
    Lazur Lazur @Lazur
    *

    Hi.

    Interpolation "should" work but to be sure you can make some restrictions that it really bring out the desired effect.

    Basically, think of the interpolation as to interpolate between two paths where you can pair up nodes you want to interpolate in between.

    Like, if one path has 5 nodes and the other 6, there is a chance the interpolation will mess things up.

    Similarly, path orientation and the sequence of the nodes can produce "unexpected" results.

    The "brute-force" method would be interpolating between two open paths. Meaning split nodes on each path so you know for sure they use the same start-end nodes.

     

    Would that work with a general shape? Yes and no. In your example you want an "equidistant" gradient following the edge of a shape. However if that distance is larger than a radii of the curve, 

    the shape of the inner path will end up "irregular".

     

    For this example you can build up the shape from two circles overlapped by a rectrangle on top of them, and

    use a single gradient definition for both the radial gradient and the linear gradient. 

    In the gradient settings there is an option making it repeating and reflected, which can match with the circles on the sides.

     

     

    The cheap and sloppy way would be using some form of blurring filter. 

     

    Another option could be by using a mesh gradient, which is really tedious and cannot adjust those handles accurately.

  3. #3
    tukykarmakar tukykarmakar @tukykarmakar
    *

    Thanks for the looking into this. I'll try split path nodes later, but for now I tried the reflected/repeating gradient. But it shows no change for this rectangle. What am I doing wrong here?

    I guess the blur technique is the most efficient one, but I need to pair it with masking as I have no control over how much the blur spreads. This also brings up another of my complaints about Inkscape, where we can't control the edge of the blur to stop at the shape's edge to create a frosted glass effect, need to use mask for that.

    Inkscape Gradients
  4. #4
    Paddy_CAD Paddy_CAD @Paddy_CAD

    You don't need a mask if you use [Filters > Blurs > Blur,,,] and choose the option [Blur content only: Yes].

  5. #5
    Lazur Lazur @Lazur

    Attaching an example for a "constructed" gradient. 

    If you select  the gradient tool (G) there is a padlock icon to affect every instances of a definition if you edit one.

    Not sure why that didn't end up in the gui you showed here.

     

    With blurring you cannot create such sharp corners and the rendering performance gets very poor if you zoom in.

    Masking in general is better avoided as for some reason masking not transfers right into pdf-s.

    Clipping can do the job this case -as a last ditch effort.

     

    With the filter editor you can set the filter so it affect only the area of the original object's visual boundaries. 

    However you are right, if you use it for somekind of distorted pattern you need to take some precautions.

    Either render the distorted part atop the unaffected object, or if you want a 100% good looking texture,

    make the original shape into a clipping object and use that to clip a larger object with some overhang which is filtered.

    It is very annoying indeed but that's how the renderer is structured.

    The filter uses a "carbon copy" of the shape rendered on screen, and not handle it as an "infinite fill" clipped by the object's shape.

    Gradient Constructed
  6. #6
    tukykarmakar tukykarmakar @tukykarmakar

    I see that I there's no uniform way to have a gradient follow the shape. I have to get creative with the tools for each case/shape. Thank you all for the help.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics How do I get a concentric gradient that follows the shape of the object?