0
$\begingroup$

I wish to show 20 circles in a vertical rectangular whose m circles are filled. n circles for example colored by green and m-n colored by red. The radius of circles are the same and can be r. The circles are not filled are empty. How do I reach this aim? I wish to specify the position of green circles and red circles manually. For example: the first be green, the second be red, the third be green and the fourth, the remainder be empty. AND NOT Random.

enter image description here

$\endgroup$
  • 1
    $\begingroup$ You can do that with a combination of Disk and Graphics. $\endgroup$ – anderstood Feb 19 '18 at 16:43
1
$\begingroup$

Here's another way:

colors = {Green, Red, Green, Sequence @@ ConstantArray[White, 17]};
r = 
  Table[Rectangle[{m, n}, RoundingRadius -> .5], {m, 1}, {n, 20}];

Graphics[{EdgeForm[Blue], Riffle[Reverse@colors, Flatten@r]},
  Frame -> True, FrameStyle -> Directive[Blue, Bold], 
 FrameTicks -> None]

enter image description here

$\endgroup$
  • $\begingroup$ You just need to specify your desired order in colors. I was doing something similar with Rectangles, so that's why I use them here instead of explicit circles (RoundingRadius->0.5 of a Rectangle[] equals a circle). $\endgroup$ – PedroSapichu Feb 19 '18 at 23:21
  • $\begingroup$ Thank you so much, your approach is very near to what I was searching, $\endgroup$ – Unbelievable Feb 20 '18 at 5:45
  • $\begingroup$ @Irreversible, glad I could help! $\endgroup$ – PedroSapichu Feb 20 '18 at 7:29
2
$\begingroup$

Here's one way:

GraphicsColumn[Table[Graphics[{RandomChoice[{Green, Red, White}],
     Disk[{i, 0}, 0.4], Black, Circle[{i, 0}, 0.4]}], {i, 20}]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you so much. But I wish to specify the position of green circles and red circles manually. For example: the first be green, the second be red, the third be green and the fourth, the remainder be empty. AND NOT Random. $\endgroup$ – Unbelievable Feb 19 '18 at 19:37
  • $\begingroup$ @Irreversible What have you tried and where did you get stuck? This answer shows the basics. You can just as easily pull the colour from another list indexed by i. $\endgroup$ – Szabolcs Feb 19 '18 at 20:34
  • $\begingroup$ @Szabolcs, I have exploited GraphicsColumn[{Graphics[Disk[]], Graphics[Disk[]], Graphics[Disk[]]}, (which is in the help Mathematica) Frame -> All], But unfortunately I had to create twenty copies of the line for specifying the position of colored circles. $\endgroup$ – Unbelievable Feb 20 '18 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.