20

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

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Murta
  • 26,275
  • 6
  • 76
  • 166

2 Answers2

18

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

halirutan
  • 112,764
  • 7
  • 263
  • 474
11
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

Nasser
  • 143,286
  • 11
  • 154
  • 359