4
$\begingroup$

Problem / background: consider the following code snippet.

pnt[fig_, n_] := {fig[[1, n]], fig[[2, n]]}
hor := {.025, .1, .25, .4, .475, .525, .6, .75, .9, .975}
ver := {.05, .20, .80, .95}
fig4 := Transpose[{
   {hor[[1]], ver[[2]], 1}, {hor[[2]], ver[[1]], 1}, {hor[[4]], 
    ver[[1]], 1}, {hor[[5]], ver[[2]], 1},
   {hor[[1]], ver[[3]], 1}, {hor[[2]], ver[[4]], 1}, {hor[[4]], 
    ver[[4]], 1}, {hor[[5]], ver[[3]], 1},
   {hor[[6]], ver[[2]], 1}, {hor[[7]], ver[[1]], 1}, {hor[[9]], 
    ver[[1]], 1}, {hor[[10]], ver[[2]], 1},
   {hor[[6]], ver[[3]], 1}, {hor[[7]], ver[[4]], 1}, {hor[[9]], 
    ver[[4]], 1}, {hor[[10]], ver[[3]], 1},
   {hor[[3]], ver[[2]], 1}, {hor[[3]], ver[[3]], 1},
   {hor[[8]], ver[[2]], 1}, {hor[[8]], ver[[3]], 1}
   }]
draw4A[fig_] := {
  BezierCurve[{pnt[fig, 1], pnt[fig, 2], pnt[fig, 3], pnt[fig, 4]}],
  BezierCurve[{pnt[fig, 5], pnt[fig, 6], pnt[fig, 7], pnt[fig, 8]}],
  BezierCurve[{pnt[fig, 9], pnt[fig, 10], pnt[fig, 11], pnt[fig, 12]}],
  BezierCurve[{pnt[fig, 13], pnt[fig, 14], pnt[fig, 15], 
    pnt[fig, 16]}],
  Line[{pnt[fig, 1], pnt[fig, 4]}],
  Line[{pnt[fig, 5], pnt[fig, 8]}],
  Line[{pnt[fig, 9], pnt[fig, 12]}],
  Line[{pnt[fig, 13], pnt[fig, 16]}]}
Graphics[draw4A[fig4]]

which draws four half-pie type of objects:

enter image description here

Question: I want to fill each part with a different, optional color different than that of the surrounding line. How can I add this fill color?

$\endgroup$
3
  • $\begingroup$ Question: for hor, ver, and fig4 your using SetDelayed, yet they're static values. Are these just place holders for more complex code, as plane Set is better in this context? $\endgroup$
    – rcollyer
    Commented Feb 16, 2012 at 18:14
  • $\begingroup$ Thank you for noticing @rcollyer. I'll have look at it. The actual code does more than this though. $\endgroup$ Commented Feb 16, 2012 at 20:51
  • $\begingroup$ I figured it was more complex and they were possibly acting as placeholders. $\endgroup$
    – rcollyer
    Commented Feb 16, 2012 at 21:51

2 Answers 2

6
$\begingroup$

I presume you are looking for FilledCurve.

enter image description here

enter image description here

$\endgroup$
2
7
$\begingroup$

Also, you can use FaceForm if you want to specify more than one directive (i.e. not just color, but opacity, etc.) for the primitive:

Graphics[{FaceForm[{Pink, Opacity[.2]}], EdgeForm[Black], 
  FilledCurve[BezierCurve[{{-1, 0}, {-1, 2}, {1, 2}, {1, 0}}]]}, 
 ImageSize -> 100]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ I gave this a vote, but now I am wondering is it necessary to use both FaceForm and EdgeForm? Can you not simply give the directives in FaceForm directly? This appears to work with other primitives. Is FilledCurve different? $\endgroup$
    – Mr.Wizard
    Commented Feb 16, 2012 at 13:59
  • $\begingroup$ I think you need both as they cannot be combined. For example you cannot specify Thickness in FaceForm, as it results in the Pink Screen of Death. $\endgroup$ Commented Feb 16, 2012 at 14:12
  • $\begingroup$ But are there any combinations that require both FaceForm and EdgeForm? You could put Thickness in either the main list or EdgeForm, right? $\endgroup$
    – Mr.Wizard
    Commented Feb 16, 2012 at 14:14
  • $\begingroup$ @Mr.Wizard I could not think of any at the moment. Proper order of naked directives in the main list usually is enough. Would be nice to find a counterexample though. $\endgroup$ Commented Feb 17, 2012 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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