6
$\begingroup$

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}]

enter image description here

$\endgroup$
6
  • $\begingroup$ Can you be more precise why your method is not very useful? It looks like it's working ... $\endgroup$
    – Domen
    Commented Aug 14, 2023 at 15:35
  • $\begingroup$ @Domen He wants the blurring delta to be continuous $\endgroup$
    – user5601
    Commented Aug 14, 2023 at 16:08
  • 1
    $\begingroup$ 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!). $\endgroup$
    – Michael E2
    Commented Aug 14, 2023 at 16:40
  • 3
    $\begingroup$ 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}] $\endgroup$
    – Michael E2
    Commented Aug 14, 2023 at 16:42
  • 1
    $\begingroup$ @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! $\endgroup$
    – Lou
    Commented Aug 16, 2023 at 13:33

4 Answers 4

5
$\begingroup$

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]] &)]

enter image description here

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

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]]]

enter image description here

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

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]

enter image description here

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]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – Lou
    Commented Aug 14, 2023 at 18:07
6
$\begingroup$

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]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.