# Alternate two colour in concentric circles

This code gives me two sets of concentric circles with respective radii of 2n and 2n-1:

With[{n = 5}, Show[Graphics[
({{Circle[{0, 0}, 2*#1]}, {Circle[{0, 0},
2*#1 - 1]}} & ) /@ Range[n]], Axes -> True]]


I would like alternating circles to be red and blue. I don't want to change anything else. But I can't figure out where to insert a PlotStyle instruction...

Any suggestions?

With[{n = 5}, Graphics[{{Red, Circle[{0, 0}, 2*#1]}, Blue, {Circle[{0, 0}, 2*#1 - 1]}} &/@
Range[n], Axes -> True]]


• Appreciated. Feeling a bit of muppet. Can't accept for 8 mins, but will then do so :-) Oct 25, 2018 at 23:23
• @RichardBurke-Ward, it happens to all of us:)
– kglr
Oct 25, 2018 at 23:24

kglr's solution is what I would have done in old Mathematica. Nowadays, I would use Riffle[]:

With[{n = 5},
Graphics[Riffle[Flatten[{Circle[{0, 0}, 2 #1 - 1], Circle[{0, 0}, 2 #1]} & /@
Range[n]], {Blue, Red}, {1, -2, 2}],
Axes -> True]]


With[{n = 5},
Graphics[
Table[{If[OddQ[i], Blue, Red], Circle[{0, 0}, i]}, {i, n * 2}],
Axes -> True]]


Using BlockMap:

With[{n = 5},
Graphics[
BlockMap[{If[OddQ[#[[1]]], Blue, Red], Circle[{0, 0}, #[[1]]]} &,
Range[2 n], 1], Axes -> True]]


table driven

With[{n = 5},
Graphics[Table[{<|True -> Blue, False -> Red|>[OddQ[i]], Circle[{0, 0}, i]}, {i, n * 2}], Axes -> True]
]


A few variations:

Clear["Global*"];
n = 5;

c1 = {If[OddQ[#], Blue, Red], Circle[{0, 0}, #]} & /@ Range[2 n];

c2 = Array[{Red, Circle[{0, 0}, 2 #], Blue,
Circle[{0, 0}, 2 # - 1]} &, {n}];

c3 = MapIndexed[{If[OddQ[First@#2], Blue, Red], Circle[{0, 0}, #1]} &,
Range[2 n]];

c4 = MapThread[{#1, Circle[{0, 0}, #2]} &
, {Sequence @@@ ConstantArray[{Blue, Red}, n]
, Range[2 n]
}
];

c5 = FoldPairList[{{If[OddQ[#1], Blue, Red],
Circle[{0, 0}, #1]}, #2} &, Range[2 n]];


Graphics[#, Axes -> True] & /@ {c1, c2, c3, c4, c5}

(* desired output x5 *)
`