Message Boards Message Boards

0
|
4337 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Fill an area in a graphic with color?

Posted 8 years ago

I have made a simple Graphics object with two lines and two bezier curves:

pic = Graphics[{
    BezierCurve[{{3, 0}, {2, 1.5}, {-.5, 2.25}, {0, 6}}],
    BezierCurve[{{3, 0}, {4, 1.5}, {6.5, 2.25}, {6, 6}}],
    Line[{{0, 6}, {6, 6}}],
    Line[{{3, 0}, {3, 6}}]}];

I'd like to fill the left side with a color and the right side with a different color. How can I do this?

I have read what relevant docs I could find, but only learned to make fills inside polygons and between axes and curves in plots.

Thank you in advance,

Mark Greenberg

POSTED BY: Mark Greenberg
2 Replies
Posted 8 years ago

Thank you, Vitaliy. It seems simple, but I could not find the function in the docs. Of course, it is there, now that I know what it is called. : )

By the way, your example has a stray line that I eliminated by reordering the points in the graphic:

pic = Graphics[{EdgeForm[{Thick, Black}],
    Red,
    FilledCurve[{BezierCurve[{{3, 0}, {2, 1.5}, {-.5, 2.25}, {0, 6}}],
       Line[{{0, 6}, {3, 6}}], Line[{{3, 6}, {3, 0}}]}],
    Blue,
    FilledCurve[{BezierCurve[{{3, 0}, {4, 1.5}, {6.5, 2.25}, {6, 6}}],
       Line[{{6, 6}, {3, 6}}], Line[{{3, 6}, {3, 0}}]}]}];

Thanks again!

POSTED BY: Mark Greenberg

You need FilledCurve for this:

Graphics[{
Red,
FilledCurve[{
BezierCurve[{{3,0},{2,1.5},{-.5,2.25},{0,6}}],
Line[{{0,6},{3,6}}],Line[{{3,0},{3,6}}]
}],
Blue,
FilledCurve[{
BezierCurve[{{3,0},{4,1.5},{6.5,2.25},{6,6}}],
Line[{{3,0},{3,6}}],Line[{{3,6},{6,6}}]
}]
}]

enter image description here

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract