# how to color edges of a convex polygon,say a square, using interpolation with respect to the color in Mathematica

How do I color edges of a convex polygon, say a square, using interpolation with respect to the color (to form parametric polynomials) in Mathematica, so that the colors displayed on the 4 edges would vary linearly (say we use three colors)?

You can use VertexColors:

coords = {{1, 2}, {3, 2}, {3, 4}, {1, 4}};
colors = {Green, Red, Blue, Orange};
verticesandcolors = Transpose /@
Partition[Transpose[Join[#, {#[]}] & /@ {coords, colors}], 2, 1];
Graphics[{Thickness[.03], Line[#, VertexColors -> #2] & @@@ verticesandcolors,
FaceForm[], EdgeForm[Black], Polygon@coords}] Alternatively, you can construct a BSplineFunction from coords and use it with ParametricPlot with a custom ColorFunction:

bsF = BSplineFunction[coords, SplineDegree -> 1, SplineClosed -> True];
cF = Blend[Transpose[{Range[0, 1, 1/4], Join[colors, {colors[]}]}], #] &;
ParametricPlot[bsF[u], {u, 0, 1}, Axes -> False,
PlotStyle -> Directive[{JoinForm["Round"], CapForm["Round"], Thickness[.05]}],
ColorFunction -> (cF[#3] &), Epilog -> {FaceForm[], EdgeForm[Black], Polygon[coords]}] • Can the function "Manipulate" be incorporated in a way that is consistent with the question described? – Chonglin Zhu Oct 21 '18 at 17:00
• @ChonglinZhu, what would you like to control in Manipulate? Colors, coordinates...? – kglr Oct 21 '18 at 17:03
• the color and the parameter goes from 0 to 1, I saw my tutor did it – Chonglin Zhu Oct 21 '18 at 18:21