2
$\begingroup$

I have the code

Graphics[{Dashed, Green, Circle[{0, 0}, .4], Black, 
  Circle[{0, 0}, .5], FaceForm[], EdgeForm[Black], 
  Rectangle[{-1, -1}, {1, 1}]}]

Which gives the output

enter image description here

However, I do not want the outer circle to be dashed. The documentation example suggests that the options are only applied to the first object after those options. So why is Dashed[] being applied to the outer circle?

$\endgroup$

1 Answer 1

10
$\begingroup$

The documentation says:

Nested lists of graphics constructs can be given. Directive specifications such as GrayLevel remain in effect only until the end of the list that contains them.

So, include Dashed and the first circle in a nested list:

Graphics[{Green, {Dashed, Circle[{0, 0}, .4]}, Black, Circle[{0, 0}, .5],
FaceForm[], EdgeForm[Black], Rectangle[{-1, -1}, {1, 1}]}]

enter image description here

$\endgroup$
3
  • $\begingroup$ And how would one know beforehand wheter or not to use a nested list with a certain option? $\endgroup$
    – ngc1300
    Dec 10, 2020 at 20:38
  • 3
    $\begingroup$ @pmac Directives in a list persist until the end of the list. I think that should be clear enough? $\endgroup$
    – Carl Woll
    Dec 10, 2020 at 20:58
  • $\begingroup$ I see how that works for most of the cases. But if my list is {Green, Dashed, Circle[{0, 0}, .4], Black, Circle[{0, 0}, .5], FaceForm[], EdgeForm[Black], Rectangle[{-1, -1}, {1, 1}]} then I get a solid rectangle. But according to that rule shouln't it be dashed? $\endgroup$
    – ngc1300
    Dec 12, 2020 at 19:47

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