# Different color for lines

please help me. I want to paint every line different color, tried many ways, but they don't works. Thank you.

Animate[
Graphics[{{Style [
Line[{{{0, 0}, {3 Cos[x], 3 Sin[x]}}, {{0, 0}, {3 Cos[x - x/10],
3 Sin[x - x/10]}}}], {Red, Blue}] }}, Axes -> True,
PlotRange -> {{-5, 5}, {-5, 5}} ], {x, 0, 2 π}]


• Structure your Graphics command like Graphics[{color1, line1, color2, line2}] Jan 2, 2017 at 21:11
• Animate[ Graphics[ Thread[{{Red, Blue}, Line /@ {{{0, 0}, {3 Cos[x], 3 Sin[x]}}, {{0, 0}, {3 Cos[x - x/10], 3 Sin[x - x/10]}}}}], Axes -> True, PlotRange -> {{-5, 5}, {-5, 5}}], {x, 0, 2 \[Pi]}] Jan 2, 2017 at 21:11

The simple solution as already given in the comments is to split the Line expression and interleave color directives:

Animate[Graphics[{{Red, Line[{{0, 0}, {3 Cos[x], 3 Sin[x]}}]},
{Blue, Line[{{0, 0}, {3 Cos[x - x/10], 3 Sin[x - x/10]}}]}}, Axes -> True,
PlotRange -> {{-5, 5}, {-5, 5}}], {x, 0, 2 π}]


In the case of more line segments there can be an advantage to preserving a single Line expression as this is typically rendered faster. To make that work with individual segment colors you can use VertexColors and specify the color for each end of each line segment:

Animate[Graphics[
Line[{{{0, 0}, {3 Cos[x], 3 Sin[x]}}, {{0, 0}, {3 Cos[x - x/10],
3 Sin[x - x/10]}}}, VertexColors -> {{Red, Red}, {Blue, Blue}}], Axes -> True,
PlotRange -> {{-5, 5}, {-5, 5}}], {x, 0, 2 π}]


A Larger example:

colors = ({#, #} & /@ RandomColor[50]);

Animate[
Graphics[
Line[{#, {0, 0}} & /@ CirclePoints[{1, x}, 50], VertexColors -> colors]
],
{x, 0, Pi/5}
]


• Hi, I'm having a slightly different problem. I've look everywhere but until now I couldn't finish this task. I've tried colordata,colorlist,vertexcolors, and several other techniques but it is still not working with my data. I want to make that the color on my curve changes for every iteration. Let say it has 3 iterations that will produce 3 different line, I want it to produce different color for each line. Can anyone help me? Jan 31, 2017 at 2:44
• @NKamaru Please post a new question with as much information as possible. Describe exactly what you want, include pictures, and show the code you are starting with. Jan 31, 2017 at 7:50