20
$\begingroup$

How can I color a BezierCurve from Red into Green just as Line does?

pts={{0,0}, {1,1}, {2,0}};
Graphics[{Thick, BezierCurve[pts], Line[{{0,0}, {2,0}}, VertexColors->{Red, Green}]}]

spLine

$\endgroup$

2 Answers 2

19
$\begingroup$

A simple line strip should be sufficient for most purposes and there you can use VertexColors as usual:

pts = {{0, 0}, {1, 1}, {2, 0}};
Graphics[{Thick, 
  Line[BezierFunction[pts] /@ #, 
    VertexColors -> (Blend[{Red, Green}, #] & /@ #)] &[Range[0, 1, .01]], 
  Line[{{0, 0}, {2, 0}}, VertexColors -> {Red, Green}]}
]

enter image description here

$\endgroup$
1
  • $\begingroup$ This was what I was looking for. tks $\endgroup$
    – Murta
    Commented Jul 31, 2013 at 11:14
11
$\begingroup$
pts = {{0, 0}, {1, 1}, {2, 0}};
f = BezierFunction[pts];
Show[
 ParametricPlot[f[t], {t, 0, 2}, ColorFunction -> Function[{x}, RGBColor[1 - x, x, 0]]], 
 Graphics[{Thick,Line[{{0, 0}, {2, 0}}, VertexColors -> {Red, Green}]}], Axes -> None
 ]

Mathematica graphics

$\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.