# How to blur a line gradually

I would like to draw a line or curve and blur it partially or gradually. AFAIK Blurring is only blurring for a complete object (like a line). Of course I can clumsily split a line in chunks like below but it's not very useful. Any ideas?

b = BezierFunction[{{0, 0}, {1, 1}, {2, 0}, {5, 5}}]
xy = Flatten[
MapIndexed[{Blurring[ First@#2/10 - 1], Line[#1]} &,
Partition[Table[b[x], {x, 0, 1, 0.02}], 2, 1]], 1];
Graphics[{Thick, Green, xy}]

• Can you be more precise why your method is not very useful? It looks like it's working ... Commented Aug 14, 2023 at 15:35
• @Domen He wants the blurring delta to be continuous Commented Aug 14, 2023 at 16:08
• CapForm["Round"] seems to do the best job, but it's not perfect (I think). -- Too bad Blurring[] does not work with VertexColors (feature request!). Commented Aug 14, 2023 at 16:40
• Not bad, but slow: b = BezierFunction[{{0, 0}, {1, 1}, {2, 0}, {5, 5}}] xy = Flatten[ MapIndexed[{Blurring[First@#2/100 - 1], Line[#1]} &, Partition[Table[b[x], {x, 0, 1, 0.002}], 2, 1]], 1]; Graphics[{Thick, Red, CapForm["Butt"], xy}] Commented Aug 14, 2023 at 16:42
• @CATrevillian yes perhaps I should have been more clear. I was focussed on blurring but the Opacity is closer to what I need. I see many nice methods are presented!
– Lou
Commented Aug 16, 2023 at 13:33

Not blurring but maybe close enough to what you want. We create a parametric function from the bezier curve via this question and apply a color function. Feel free to experiment with it. Potentially you can combine it with this question to make the function wider and use the opacity of the color function to achieve a similar effect.

Clear[points, b, p]
points = {{0, 0}, {1, 1}, {2, 0}, {5, 5}};
b = BezierFunction[points];
p[t_] := Sum[points[[i + 1]] BernsteinBasis[3, i, t], {i, 0, 3}];
ParametricPlot[p[t], {t, 0, 1},
ColorFunction -> (Hue[0.3, 1, 1, Max[1 - #, 0.1]] &)]

• I think this is closest to what I meant indeed. I now need to figger out what the BernsteinBasis is..
– Lou
Commented Aug 16, 2023 at 13:36

Here is a possible approach using overlapping lines

b = BezierFunction[{{0, 0}, {1, 1}, {2, 0}, {5, 5}}];
curves = Table[n b[x], {n, 0.9, 1.1, .01}];
styles = Table[{Blue, Opacity[n]}, {n, .01, .4, .04}];

ParametricPlot[curves, {x, 0, 2},
PlotStyle -> Join[styles, {{Blue, Opacity[0.4]}}, Reverse[styles]]]

• Nice idea! I would like to keep the width more equal.
– Lou
Commented Aug 15, 2023 at 6:38

I will happily delete this if it's not really what you're looking for, but you could convert the plot to an image and then blur with increasingly large kernel Gaussian filters:

b = BezierFunction[{{0, 0}, {1, 1}, {2, 0}, {5, 5}}]
p = ParametricPlot[b[t], {t, 0, 1}, Axes -> False]

img = Import["https://i.sstatic.net/hHgov.png"]
gF[i_, ker_] := GaussianFilter[i, ker]
takeParts =
Table[ImageTake[img, {1, 720}, {(36*(x - 1) + 1), 36*x}], {x, 20}];
blurred = Table[gF[takeParts[[x]], x/2], {x, Length@takeParts}]
ImageAssemble[blurred]

• thx. I would prefer a graphic approach instead of image. That said I like this approach but wonder how it would work with many closely aligned lines etc.
– Lou
Commented Aug 14, 2023 at 18:07

Following a similar approach to kglr's (now deleted) answer, just with different choices of ColorFunction et al.:

width = 0.1;
parallel[t_, d_] := b[t] - d Cross[b'[t]]/Norm[b'[t]]
ParametricPlot[parallel[t, d], {t, 0, 1}, {d, - width , width},
ColorFunction ->
Function[{x, y, u, v},
Directive[
Opacity[(1.5 - u) Exp[-(v - 1/2)^2/(2 (u + 0.1) width)^2]]]],
BoundaryStyle -> None]