# Drawing a circle subdivided into arcs of different colors

I would like to draw a circle and have different parts in different colors. Which part has which color should be changeable with sliders.

I've managed to do two colors, but would like to have three or four.

Manipulate[Show[
Graphics[{Circle[], {Black, [email protected], Point@{Cos[Pi/2], Sin[Pi/2]}}}],
Graphics[{Circle[], {Black, [email protected], Point@{Cos[3 Pi/2], Sin[3 Pi/2]}}}],
Graphics[{Black, AbsoluteThickness[1], Circle[{0, 0}, 1]}],
Graphics[{Red, AbsoluteThickness[4], Circle[{0, 0}, 1, {0 Degree, 360 Degree}]}],
Graphics[{Blue, AbsoluteThickness[4], Circle[{0, 0}, 1, {r Degree, l Degree}]}],
PlotRange -> {{-1.3, 1.3}, {-1.3, 1.3}},
ImageSize -> 250],
{{l, 180, "L"}, r, 360 + r},
{{r, 0, "R"}, l - 360, l},
ControlPlacement -> Left]


Thank you for any suggestions!

• Take a look at TrackingFunction. You need to decide which parts are reduced when other changes.
– Kuba
Commented Oct 15, 2020 at 10:19
• Something like: n = 5 dph = 2 Pi/n; Graphics[{Thickness[0.05], Table[{Hue[1/i], Circle[{0, 0}, 1, {(i - 1) dph, i dph}]}, {i, n}]}] Commented Oct 15, 2020 at 10:23

Manipulate[
With[{arc = Arrow@Table[AngleVector[t], {t, If[# < #2, #, # - 2 Pi], #2, .005}] &},
Graphics[{
Thick,
Riffle[{Red, Green, Blue, Yellow}, arc@@@Partition[Mod[ArcTan@@@pt, 2 Pi], 2, 1, 1]]
}, PlotRange -> 1.2]
],
{{pt, {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}}, Locator,
TrackingFunction -> (Do[pt[[i]] = Normalize[#[[i]]], {i, 4}]; &)}
]


Another way, compatibility with prior versions

DynamicModule[{pt = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}, arc},
arc = Circle[{0, 0}, 1, {If[# < #2, #, # - 2 Pi], #2}] &;
Graphics[{
Thick, Dynamic@Riffle[{Red, Green, Blue, Yellow},
arc@@@Partition[Mod[ArcTan@@@pt, 2 Pi], 2, 1, 1]],
Array[Function[i, Locator[Dynamic[pt[[i]], (pt[[i]] = Normalize[#]) &]]], 4]
}, PlotRange->1.2
]
] // Deploy

circle[t_] = {Cos[2 Pi*t], Sin[2 Pi*t]};
plotArc[{tmin_, tmax_}, color_] :=
ParametricPlot[circle[t], {t, tmin, tmax}, PlotStyle -> color]
Show[plotArc[{0., 0.3}, Blue], plotArc[{0.3, 0.5}, Red],
plotArc[{0.5, 0.8}, Green], plotArc[{0.8, 1}, Orange],
PlotRange -> {-1, 1}]


Wrapped in a function that you can use with Manipulate:

plotCircle[ts_, colors_] :=
With[{ts2 = ts~Join~{1 + ts[[1]]}},
Show[Table[
plotArc[{ts2[[i]], ts2[[i + 1]]}, colors[[i]]], {i, 1,
Length[ts]}], PlotRange -> {-1, 1}]]


Example:

plotCircle[{0.2, 0.5, 0.8}, {Blue, Green, Red}]


You can use a single ParametricPlot with the options MeshFunctions + Mesh + MeshShading to get circular arcs:

SeedRandom[1]
mesh = RandomSample[Subdivide[0, 2 Pi, 50], 5];

ParametricPlot[{Cos[t], Sin[t]},{t, 0 , 2 Pi},
MeshFunctions -> {#3 &},
Mesh -> {mesh},
MeshStyle -> Opacity[0],